一、目的

一台服务器和一台触摸屏客户端,之间以TCP或串口相连,客户端开发一款软件,模拟硬键盘控制,以控制服务器端功能。

二、基本功能

1.客户端模拟硬键盘,可向服务器发送按键编码、按下和弹起的状态

2.模拟按键的编码、名称、大小、位置、颜色等可以定义和随意更换(换肤)

3.按键按下和弹起时的事件可以定制

4.二次开发功能以完成【1】、【2】、【3】的定制开发

三、界面

1.主页面

一个用Winform进行业务定制二次开发实现实例

2.属性定义页面

一个用Winform进行业务定制二次开发实现实例

3.其他页面

模板定义页面

一个用Winform进行业务定制二次开发实现实例

事件定义页面

一个用Winform进行业务定制二次开发实现实例

四、功能

1.按键追加:click【ADD】

一个用Winform进行业务定制二次开发实现实例

2.在按键上click鼠标右键修改属性和事件信息

五、代码

一个用Winform进行业务定制二次开发实现实例

1.主程序

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using System.IO;
using System.Reflection;

namespace weitest
{
    public partial class KeyImitate : Form
    {
        public const int total = 136;
        Boolean bMouseDown;
        Boolean bChangeSizeMode;
        Boolean bMoveMode;


        Point pt;
        int cur;

        bForm bform = new bForm();

        Button[] weifq = new Button[total];
        bProperty[] bproperty = new bProperty[total+1];
        bEvent[] bevent = new bEvent[total+1];

        public tmpBuf tmpbuf = new tmpBuf();

        public KeyImitate()
        {
            InitializeComponent();
        }

        private void KeyImitate_Load(object sender, EventArgs e)
        {
            XmlRW xml = new XmlRW();
            xml.ReadFormList(ref bform);

            this.BackColor = SystemColors.Control;
            this.Text = bform.title;
            if (bform.style.Equals("1")|| bform.style.Equals("2"))
            {
                this.FormBorderStyle = FormBorderStyle.FixedDialog;
                this.AutoSize = false;
                this.MaximizeBox = false;
                this.MinimizeBox = false;
                
                if (bform.style.Equals("1"))
                {
                    label1.Visible = false;
                    label1.Enabled = false;
                }
                else
                {
                    label1.Visible = true;
                    label1.Enabled = true;
                }
            }
            else
            {
                MenuStrip ms = new MenuStrip();
                ms.Items.Add("Add", null, menu_click);
                this.MainMenuStrip = ms;
                this.Controls.Add(ms);
            }


            if (null != bform.title && !bform.title.Equals("error"))
            {
                this.Text = bform.title;
                this.Left = bform.fPos.X;
                this.Top = bform.fPos.Y;
                this.Width = bform.fSize.X;
                this.Height = bform.fSize.Y;
            }
            xml.ReadButtonList(ref bproperty, ref bevent);
            for(int i = 0; i < total; i++)
            {
                if (null == bproperty[i].bName || bproperty[i].bName.Equals("error")) break;
                weifq[i] = new Button();
                weifq[i].Text = bproperty[i].bName;
                xml.setColor(weifq[i], bproperty[i].bColor);
                weifq[i].Tag = bproperty[i].bID;
                setClick(i);
                weifq[i].MouseUp += gxzk_MouseUp;
                weifq[i].MouseMove += gxzk_MouseMove;
                weifq[i].Left = bproperty[i].bPos.X;
                weifq[i].Top = bproperty[i].bPos.Y;
                weifq[i].Width = bproperty[i].bSize.X;
                weifq[i].Height = bproperty[i].bSize.Y;
                this.Controls.Add(weifq[i]);
                if (File.Exists(bproperty[i].pngUP))
                {
                    Bitmap bm = new Bitmap(bproperty[i].pngUP);
                    weifq[i].BackgroundImage = bm;
                    weifq[i].BackgroundImageLayout = ImageLayout.Stretch;


                    weifq[i].FlatStyle = FlatStyle.Flat;
                    weifq[i].FlatAppearance.BorderSize = 0;
                    weifq[i].FlatAppearance.MouseDownBackColor = this.BackColor;
                    weifq[i].FlatAppearance.MouseOverBackColor = this.BackColor;
                    weifq[i].FlatAppearance.BorderColor = this.BackColor;
                    weifq[i].BackColor = this.BackColor;


                }
            }
        }
        private void gxzk_MouseUp(Object sender,MouseEventArgs e)
        {
            bMouseDown = false;
            bMoveMode = false;
            if (e.Button == MouseButtons.Left)
            {
                if (File.Exists(bproperty[cur].pngUP))
                {
                    Bitmap bm = new Bitmap(bproperty[cur].pngUP);
                    weifq[cur].BackgroundImage = bm;
                    weifq[cur].BackgroundImageLayout = ImageLayout.Stretch;


                    weifq[cur].FlatStyle = FlatStyle.Flat;
                    weifq[cur].FlatAppearance.BorderSize = 0;
                    weifq[cur].FlatAppearance.MouseDownBackColor = this.BackColor;
                    weifq[cur].FlatAppearance.MouseOverBackColor = this.BackColor;
                    weifq[cur].FlatAppearance.BorderColor = this.BackColor;
                    weifq[cur].BackColor = this.BackColor;
                }
                label1.Text = "click up:" + click(cur+1, 1);
            }
            return;
        }
        private void gxzk_MouseDown(int i,MouseEventArgs e)
        {
            bMouseDown = true;
            pt = Cursor.Position;
            if (e.Button == MouseButtons.Left)
            {
                if (File.Exists(bproperty[i].pngDN))
                {
                    Bitmap bm = new Bitmap(bproperty[i].pngDN);
                    weifq[i].BackgroundImage = bm;
                    weifq[i].BackgroundImageLayout = ImageLayout.Stretch;


                    weifq[i].FlatStyle = FlatStyle.Flat;
                    weifq[i].FlatAppearance.BorderSize = 0;
                    weifq[i].FlatAppearance.MouseDownBackColor = this.BackColor;
                    weifq[i].FlatAppearance.MouseOverBackColor = this.BackColor;
                    weifq[i].FlatAppearance.BorderColor = this.BackColor;
                    weifq[i].BackColor = this.BackColor;
                }
                label1.Text = "click down:" + click(i+1, 2);
            }
            if (!bform.style.Equals("1")&& !bform.style.Equals("2"))
            {
                if (e.Button == MouseButtons.Right)
                {
                    tmpbuf.pngup = bproperty[i].pngUP;
                    tmpbuf.pngdn = bproperty[i].pngDN;
                    tmpbuf.bevent = bevent[i];
                    dg tmp = new dg(weifq[i]);
                    tmp.PtmpBuf = tmpbuf;
                    
                    Point p1;
                    Point p3;
                    p1 = this.Location;
                    p3 = new Point(p1.X + weifq[i].Left + this.Width - this.ClientRectangle.Width + weifq[i].Width / 2,
                        p1.Y+weifq[i].Top+this.Height-this.ClientRectangle.Height+weifq[i].Height/2);
                    tmp.Location = p3;
                    tmp.StartPosition = FormStartPosition.Manual;
                    tmp.ShowDialog();
                    if (weifq[i].Text.Equals("error"))
                    {
                        this.Controls.Remove(weifq[i]);
                    }
                    bproperty[i].pngUP = tmp.PtmpBuf.pngup;
                    bproperty[i].pngDN = tmp.PtmpBuf.pngdn;


                    bevent[i] = tmp.PtmpBuf.bevent;
                }
            }
            return;
        }
        private void setClick(int i)
        {
            switch (i)
            {
                case 0:
                    weifq[i].MouseDown += gxzk_MouseDown1;
                    break;
                case 1:
                    weifq[i].MouseDown += gxzk_MouseDown2;
                    break;
                case 2:
                    weifq[i].MouseDown += gxzk_MouseDown3;
                    break;
                case 3:
                    weifq[i].MouseDown += gxzk_MouseDown4;
                    break;
                case 4:
                    weifq[i].MouseDown += gxzk_MouseDown5;
                    break;
                case 5:
                    weifq[i].MouseDown += gxzk_MouseDown6;
                    break;
                case 6:
                    weifq[i].MouseDown += gxzk_MouseDown7;
                    break;
                case 7:
                    weifq[i].MouseDown += gxzk_MouseDown8;
                    break;
                case 8:
                    weifq[i].MouseDown += gxzk_MouseDown9;
                    break;
                case 9:
                    weifq[i].MouseDown += gxzk_MouseDown10;
                    break;
            }
            return;
        }
        private void gxzk_MouseDown1(object sender, MouseEventArgs e)
        {
            pt = Cursor.Position;
            cur = 0;
            gxzk_MouseDown(cur, e);
        }
        private void gxzk_MouseDown2(object sender, MouseEventArgs e)
        {
            pt = Cursor.Position;
            cur = 1;
            gxzk_MouseDown(cur, e);
        }
        private void gxzk_MouseDown3(object sender, MouseEventArgs e)
        {
            pt = Cursor.Position;
            cur = 2;
            gxzk_MouseDown(cur, e);
        }
        private void gxzk_MouseDown4(object sender, MouseEventArgs e)
        {
            pt = Cursor.Position;
            cur = 3;
            gxzk_MouseDown(cur, e);
        }
        private void gxzk_MouseDown5(object sender, MouseEventArgs e)
        {
            pt = Cursor.Position;
            cur = 4;
            gxzk_MouseDown(cur, e);
        }
        private void gxzk_MouseDown6(object sender, MouseEventArgs e)
        {
            pt = Cursor.Position;
            cur = 5;
            gxzk_MouseDown(cur, e);
        }
        private void gxzk_MouseDown7(object sender, MouseEventArgs e)
        {
            pt = Cursor.Position;
            cur = 6;
            gxzk_MouseDown(cur, e);
        }
        private void gxzk_MouseDown8(object sender, MouseEventArgs e)
        {
            pt = Cursor.Position;
            cur = 7;
            gxzk_MouseDown(cur, e);
        }
        private void gxzk_MouseDown9(object sender, MouseEventArgs e)
        {
            pt = Cursor.Position;
            cur = 8;
            gxzk_MouseDown(cur, e);
        }
        private void gxzk_MouseDown10(object sender, MouseEventArgs e)
        {
            pt = Cursor.Position;
            cur = 9;
            gxzk_MouseDown(cur, e);
        }
        private void menu_click(Object sender,EventArgs e)
        {
            for(int i = 0; i < total; i++)
            {
                if (null == bproperty[i].bName|| bproperty[i].bName.Equals("error"))
                {
                    weifq[i] = new Button();
                    bproperty[i].bName = "name" + i;
                    bproperty[i].bColor = "Red";
                    bproperty[i].bID = "gxzk1";
                    bproperty[i].bPos = new Point(30, 60);
                    bproperty[i].bSize = new Point(100, 50);
                    bproperty[i].pngDN = "";
                    bproperty[i].pngUP = "";


                    bevent[i].bDll = @"C:\app\workspace\weitest\EventLib\bin\Release\EventLib.dll";
                    bevent[i].bNS = "gxzkevent";
                    bevent[i].bClass = "EventLib";
                    bevent[i].bMethodup = "gxzk" + (i + 1);
                    bevent[i].bParameterup = "UP:this is the par of " + (i + 1) + " th";
                    bevent[i].bMethoddn = "gxzk" + (i + 1);
                    bevent[i].bParameterdn = "DN:this is the par of " + (i + 1) + " th";
                    this.Controls.Add(weifq[i]);


                    XmlRW xml = new XmlRW();
                    weifq[i].Text = bproperty[i].bName;
                    weifq[i].Tag = bproperty[i].bID;
                    xml.setColor(weifq[i], bproperty[i].bColor);
                    setClick(i);
                    weifq[i].MouseUp += gxzk_MouseUp;
                    weifq[i].MouseMove += gxzk_MouseMove;
                    weifq[i].Left = bproperty[i].bPos.X;
                    weifq[i].Top = bproperty[i].bPos.Y;
                    weifq[i].Width = bproperty[i].bSize.X;
                    weifq[i].Height = bproperty[i].bSize.Y;


                    bproperty[i + 1].bName = "error";
                    return;
                }
            }
            return;
        }


        private void gxzk_MouseMove(object sender, MouseEventArgs e)
        {
            bMoveMode = true;
            if (bform.style.Equals("1")|| bform.style.Equals("2")) return;
            if (!bMouseDown)
            {
                int right = ((Control)sender).Width;
                int bottom = ((Control)sender).Height;
                if (e.X > (right - 10) && e.Y > (bottom - 10))
                {
                    ((Control)sender).Cursor = Cursors.SizeNWSE;
                    bChangeSizeMode = true;
                }
                else if (e.X > (right - 10))
                {
                    ((Control)sender).Cursor = Cursors.VSplit;
                    bChangeSizeMode = true;
                }
                else if (e.Y > (bottom - 10))
                {
                    ((Control)sender).Cursor = Cursors.HSplit;
                    bChangeSizeMode = true;
                }
                else
                {
                    ((Control)sender).Cursor = Cursors.SizeAll;
                    bChangeSizeMode = false;
                }
            }


            if (bMouseDown && bMoveMode)
            {
                if (bChangeSizeMode)
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        if (((Control)sender).Cursor == Cursors.VSplit)
                        {
                            ((Control)sender).Width = e.X;
                        }
                        else if (((Control)sender).Cursor == Cursors.HSplit)
                        {
                            ((Control)sender).Height = e.Y;
                        }
                        else
                        {
                            ((Control)sender).Width = e.X;
                            ((Control)sender).Height = e.Y;
                        }
                        ((Control)sender).Tag = ((Control)sender).Width + ":" + ((Control)sender).Height + ":" + ((Control)sender).Left + ":" + ((Control)sender).Top + ":" + ((Control)sender).Font.Size;
                    }
                }
                else
                {
                    if (e.Button == MouseButtons.Left)
                    {
                        
                        int px = Cursor.Position.X - pt.X;
                        int py = Cursor.Position.Y - pt.Y;
                        ((Control)sender).Location = new Point(((Control)sender).Location.X + px, ((Control)sender).Location.Y + py);
                        pt = Cursor.Position;
                    }
                }
            }
        }


        private void weifq_MouseDown(object sender, MouseEventArgs e)
        {
            bMouseDown = true;
            pt = Cursor.Position;


        }


        private void weifq_MouseUp(object sender, MouseEventArgs e)
        {
            bMouseDown = false;
            bMoveMode = false;
        }


        private void KeyImitate_FormClosing(object sender, FormClosingEventArgs e)
        {
            DialogResult rtn;
            XmlRW xml = new XmlRW();


            if (bform.style.Equals("1")|| bform.style.Equals("2"))
            {
                rtn = MessageBox.Show("exit?", "key control", MessageBoxButtons.OKCancel);
                if (rtn == DialogResult.OK)
                {
                    e.Cancel = false;
                }
                else
                {
                    e.Cancel = true;
                }
            }
            else
            {
                rtn = MessageBox.Show("final version?", "key control", MessageBoxButtons.YesNoCancel);
                if (rtn == DialogResult.Yes)
                {
                    bform.style = "1";
                    e.Cancel = false;
                }else if (rtn == DialogResult.No)
                {
                    bform.style = "0";
                    e.Cancel = false;
                }
                else
                {
                    bform.style = "2";
                    e.Cancel = true;
                }
                if (bform.style.Equals("0") || bform.style.Equals("1"))
                {
                    for (int i = 0; i < total; i++)
                    {
                        if (null == bproperty[i].bName || bproperty[i].bName.Equals("error") || bproperty[i].bName.Equals("")) break;
                        bproperty[i].bName = weifq[i].Text;
                        bproperty[i].bID = "" + weifq[i].Tag;
                        bproperty[i].bColor = xml.getColor(weifq[i]);
                        bproperty[i].bPos.X = weifq[i].Left;
                        bproperty[i].bPos.Y = weifq[i].Top;
                        bproperty[i].bSize.X = weifq[i].Width;
                        bproperty[i].bSize.Y = weifq[i].Height;
                    }
                    bform.title = this.Text;
                    bform.fPos = new Point(this.Left, this.Top);
                    bform.fSize = new Point(this.Width, this.Height);
                    xml.WriteFormList(bproperty, bevent, bform);
                }
            }
        }
        private string click(int num,int updown)
        {
            //up:1 dn:2
            string bDll = bevent[num - 1].bDll;
            string bNS = bevent[num - 1].bNS;
            string bClass = bevent[num - 1].bClass;
            string bMethod;
            string bParameter;
            if (updown == 1)
            {
                bMethod = bevent[num - 1].bMethodup;
                bParameter = bevent[num - 1].bParameterup;
            }
            else
            {
                bMethod = bevent[num - 1].bMethoddn;
                bParameter = bevent[num - 1].bParameterdn;
            }
            if (!File.Exists(bDll))
            {
                return "" + "dynamic Dll file not exists!" + " 1(up) 2(down):" + updown;
            }
            Assembly assembly = Assembly.LoadFile(bDll);
            Type type = assembly.GetType(bNS + "." + bClass);
            object instance = assembly.CreateInstance(bNS + "." + bClass);
            Type[] params_type = new Type[1];
            params_type[0] = Type.GetType("System.String");
            Object[] params_obj = new Object[1];
            params_obj[0] = bParameter;
            object value;


            if (null == bParameter || bParameter.Equals(""))
            {
                value = type.GetMethod(bMethod).Invoke(instance, null);
            }
            else
            {
                value = type.GetMethod(bMethod, params_type).Invoke(instance, params_obj);
            }


            return "" + value + " 1(up) 2(down):" + updown;
        }


    }

}

2.属性编辑程序

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;


using System.IO;
using System.Reflection;


namespace weitest
{
    public partial class dg : Form
    {
        Button abc;
        private tmpBuf tmpb;
        public dg(Button abc)
        {
            this.abc = abc;
            InitializeComponent();
        }
        public tmpBuf PtmpBuf
        {
            set { tmpb = value; }
            get { return tmpb; }
        }
        private void dg_Load(object sender, EventArgs e)
        {
            XmlRW xml = new XmlRW();
            this.ControlBox = false;
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            pngUP.Text = tmpb.pngup;
            pngDN.Text = tmpb.pngdn;


            bDll.Text = tmpb.bevent.bDll;
            bNS.Text = tmpb.bevent.bNS;
            bClass.Text = tmpb.bevent.bClass;
            bMethodup.Text = tmpb.bevent.bMethodup;
            bParameterup.Text = tmpb.bevent.bParameterup;
            bMethoddn.Text = tmpb.bevent.bMethoddn;
            bParameterdn.Text = tmpb.bevent.bParameterdn;


            bName.Text = abc.Text;
            bID.Text = "" + abc.Tag;
            posX0.Text = "" + abc.Left;
            posY0.Text = "" + abc.Top;
            sizeX.Text = "" + abc.Width;
            sizeY.Text = "" + abc.Height;
            xml.setCombox(bColor);
            bColor.Text = xml.getColor(abc);
        }


        private void button1_Click(object sender, EventArgs e)
        {
            abc.Text = bName.Text;
            abc.Tag = bID.Text;
            // posX0.Text;
            abc.Left = Convert.ToInt32(posX0.Text);
            abc.Top = Convert.ToInt32(posY0.Text);
            abc.Width = Convert.ToInt32(sizeX.Text);
            abc.Height = Convert.ToInt32(sizeY.Text);


            XmlRW xml = new XmlRW();
            xml.setColor(abc, bColor.Text);
            tmpb.pngup = pngUP.Text;
            tmpb.pngdn = pngDN.Text;
            tmpb.bevent.bDll = bDll.Text;
            tmpb.bevent.bNS = bNS.Text;
            tmpb.bevent.bClass = bClass.Text;
            tmpb.bevent.bMethodup = bMethodup.Text;
            tmpb.bevent.bParameterup = bParameterup.Text;
            tmpb.bevent.bMethoddn = bMethoddn.Text;
            tmpb.bevent.bParameterdn = bParameterdn.Text;


            if (File.Exists(pngUP.Text))
            {
                Bitmap bm = new Bitmap(pngUP.Text);
                abc.BackgroundImage = bm;
                abc.BackgroundImageLayout = ImageLayout.Stretch;


                abc.FlatStyle = FlatStyle.Flat;
                abc.FlatAppearance.BorderSize = 0;
                abc.FlatAppearance.MouseDownBackColor = this.BackColor;
                abc.FlatAppearance.MouseOverBackColor = this.BackColor;
                abc.FlatAppearance.BorderColor = this.BackColor;
                abc.BackColor = this.BackColor;
            }
        }


        private void button5_Click(object sender, EventArgs e)
        {
            this.Close();
        }


        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Title = "open pattern Up";
            ofd.ShowHelp = true;
            ofd.Filter = "pattern file|*.png|all file|*.*";
            ofd.FilterIndex = 1;
            ofd.RestoreDirectory = false;
            ofd.InitialDirectory = @"c:\";
            ofd.Multiselect = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                pngUP.Text = ofd.FileNames[0];
                if (ofd.FileNames.Length > 1)
                {
                    pngDN.Text = ofd.FileNames[1];
                }
                else
                {
                    if (ofd.ShowDialog() == DialogResult.OK)
                    {
                        pngDN.Text = ofd.FileNames[0];
                    }
                }
            }
        }


        private void button3_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Title = "open dll";
            ofd.ShowHelp = true;
            ofd.Filter = "dll file|*.dll|all file|*.*";
            ofd.FilterIndex = 1;
            ofd.RestoreDirectory = false;
            ofd.InitialDirectory = @"c:\";
            ofd.Multiselect = true;
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                bDll.Text = ofd.FileName;
            }
        }


        private void bDll_TextChanged(object sender, EventArgs e)
        {
            if (!File.Exists(bDll.Text))
            {
                return;
            }
            Assembly assembly = Assembly.LoadFile(bDll.Text);
            bNS.Text = assembly.GetTypes()[0].Namespace;
            bClass.Text = assembly.GetTypes()[0].Name;
        }


        private void button4_Click(object sender, EventArgs e)
        {
            abc.Text = "error";
            Close();
        }
    }

}

3.XML文件管理程序

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Xml;


using System.Windows.Forms;
using System.Drawing;


using System.IO;


namespace weitest
{
    struct bProperty
    {
        public string bName;
        public string bID;
        public Point bPos;
        public Point bSize;
        public string pngUP;
        public string pngDN;
        public string bColor;
    }
    public struct bEvent
    {
        public string bDll;
        public string bNS;
        public string bClass;
        public string bMethodup;
        public string bParameterup;
        public string bMethoddn;
        public string bParameterdn;
    }
    struct bForm
    {
        public string style;
        public string title;
        public Point fPos;
        public Point fSize;
    }
    public struct tmpBuf
    {
        public string pngup;
        public string pngdn;
        public bEvent bevent;
    }
    class XmlRW
    {
        public const int total = 136;
        string formFile = Path.GetDirectoryName(Process.GetCurrentProcess().MainModule.FileName) + "\\wei.xml";


        public void WriteFormList(bProperty[] bproperty,bEvent[] bevent,bForm bform)
        {
            XmlDataDocument doc = new XmlDataDocument();
            XmlDeclaration dec = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
            doc.AppendChild(dec);
            XmlElement root = doc.CreateElement("Form");
            doc.AppendChild(root);


            XmlElement mainform = doc.CreateElement("mainform");
            mainform.SetAttribute("id", "1");


            XmlElement mainformname = doc.CreateElement("style");
            XmlText title = doc.CreateTextNode(bform.style);
            mainformname.AppendChild(title);
            mainform.AppendChild(mainformname);


            mainformname = doc.CreateElement("title");
            title = doc.CreateTextNode("按键模拟");
            mainformname.AppendChild(title);
            mainform.AppendChild(mainformname);


            XmlElement msizex = doc.CreateElement("X0");
            XmlText mx = doc.CreateTextNode(""+bform.fPos.X);
            msizex.AppendChild(mx);
            mainform.AppendChild(msizex);
            msizex = doc.CreateElement("Y0");
            mx = doc.CreateTextNode(""+bform.fPos.Y);
            msizex.AppendChild(mx);
            mainform.AppendChild(msizex);


            msizex = doc.CreateElement("X");
            mx = doc.CreateTextNode(""+ bform.fSize.X);
            msizex.AppendChild(mx);
            mainform.AppendChild(msizex);
            msizex = doc.CreateElement("Y");
            mx = doc.CreateTextNode(""+ bform.fSize.Y);
            msizex.AppendChild(mx);
            mainform.AppendChild(msizex);


            root.AppendChild(mainform);


            for (int i = 0; i < total; i++)
            {
                if (null == bproperty[i].bName || bproperty[i].bName.Equals("") ||
                    bproperty[i].bName.Equals(string.Empty) || bproperty[i].bName.Equals("error")) break;
                mainform = doc.CreateElement("button");
                mainform.SetAttribute("id", "" + (i + 1));
                mainformname = doc.CreateElement("title");
                title = doc.CreateTextNode(bproperty[i].bName);
                mainformname.AppendChild(title);
                mainform.AppendChild(mainformname);


                mainformname = doc.CreateElement("color");
                title = doc.CreateTextNode(bproperty[i].bColor);
                mainformname.AppendChild(title);
                mainform.AppendChild(mainformname);


                mainformname = doc.CreateElement("enc");
                title = doc.CreateTextNode(bproperty[i].bID);
                mainformname.AppendChild(title);
                mainform.AppendChild(mainformname);


                mainformname = doc.CreateElement("patternup");
                title = doc.CreateTextNode(bproperty[i].pngUP);
                mainformname.AppendChild(title);
                mainform.AppendChild(mainformname);


                mainformname = doc.CreateElement("patterndn");
                title = doc.CreateTextNode(bproperty[i].pngDN);
                mainformname.AppendChild(title);
                mainform.AppendChild(mainformname);


                mainformname = doc.CreateElement("dllpath");
                title = doc.CreateTextNode(bevent[i].bDll);
                mainformname.AppendChild(title);
                mainform.AppendChild(mainformname);


                mainformname = doc.CreateElement("namespace");
                title = doc.CreateTextNode(bevent[i].bNS);
                mainformname.AppendChild(title);
                mainform.AppendChild(mainformname);


                mainformname = doc.CreateElement("class");
                title = doc.CreateTextNode(bevent[i].bClass);
                mainformname.AppendChild(title);
                mainform.AppendChild(mainformname);


                mainformname = doc.CreateElement("methodup");
                title = doc.CreateTextNode(bevent[i].bMethodup);
                mainformname.AppendChild(title);
                mainform.AppendChild(mainformname);


                mainformname = doc.CreateElement("parameterup");
                title = doc.CreateTextNode(bevent[i].bParameterup);
                mainformname.AppendChild(title);
                mainform.AppendChild(mainformname);


                mainformname = doc.CreateElement("methoddn");
                title = doc.CreateTextNode(bevent[i].bMethoddn);
                mainformname.AppendChild(title);
                mainform.AppendChild(mainformname);


                mainformname = doc.CreateElement("parameterdn");
                title = doc.CreateTextNode(bevent[i].bParameterdn);
                mainformname.AppendChild(title);
                mainform.AppendChild(mainformname);


                msizex = doc.CreateElement("X0");
                mx = doc.CreateTextNode(""+bproperty[i].bPos.X);
                msizex.AppendChild(mx);
                mainform.AppendChild(msizex);
                msizex = doc.CreateElement("Y0");
                mx = doc.CreateTextNode("" + bproperty[i].bPos.Y);
                msizex.AppendChild(mx);
                mainform.AppendChild(msizex);


                msizex = doc.CreateElement("X");
                mx = doc.CreateTextNode("" + bproperty[i].bSize.X);
                msizex.AppendChild(mx);
                mainform.AppendChild(msizex);
                msizex = doc.CreateElement("Y");
                mx = doc.CreateTextNode("" + bproperty[i].bSize.Y);
                msizex.AppendChild(mx);
                mainform.AppendChild(msizex);


                root.AppendChild(mainform);
            }
            doc.Save(formFile);
        }
        public void ReadFormList(ref bForm bform)
        {
            if (!File.Exists(formFile))
            {
                bform.style = "error";
                bform.fPos = new Point(200, 200);
                bform.fSize = new Point(200, 200);
                return;
            }
            XmlDataDocument doc = new XmlDataDocument();
            doc.Load(formFile);
            XmlElement root = doc.DocumentElement;
            XmlNodeList lst = root.GetElementsByTagName("mainform");
            foreach (XmlNode node in lst)
            {
                string id = ((XmlElement)node).GetAttribute("id");
                if (id.Equals("1"))
                {
                    bform.style = ((XmlElement)node).GetElementsByTagName("style")[0].InnerText;
                    bform.title = ((XmlElement)node).GetElementsByTagName("title")[0].InnerText;
                    string X0 = ((XmlElement)node).GetElementsByTagName("X0")[0].InnerText;
                    string Y0 = ((XmlElement)node).GetElementsByTagName("Y0")[0].InnerText;
                    string X = ((XmlElement)node).GetElementsByTagName("X")[0].InnerText;
                    string Y = ((XmlElement)node).GetElementsByTagName("Y")[0].InnerText;


                    bform.fPos = new Point(Convert.ToInt32(X0), Convert.ToInt32(Y0));
                    bform.fSize = new Point(Convert.ToInt32(X), Convert.ToInt32(Y));
                    return;
                }


            }
            bform.style = "error";
            bform.fPos = new Point(200, 200);
            bform.fSize = new Point(200, 200);
            return;
        }
        public void ReadButtonList(ref bProperty[] bproperty,ref bEvent[] bevent)
        {
            if (!File.Exists(formFile)) return;
            XmlDataDocument doc = new XmlDataDocument();
            doc.Load(formFile);
            XmlElement root = doc.DocumentElement;
            XmlNodeList lst = root.GetElementsByTagName("button");
            int order = 0;
            foreach (XmlNode node in lst)
            {
                string id = ((XmlElement)node).GetAttribute("id");
                bproperty[order].bName = ((XmlElement)node).GetElementsByTagName("title")[0].InnerText;
                bproperty[order].bPos = new Point(Convert.ToInt32(((XmlElement)node).GetElementsByTagName("X0")[0].InnerText),
                    Convert.ToInt32(((XmlElement)node).GetElementsByTagName("Y0")[0].InnerText));
                bproperty[order].bSize = new Point(Convert.ToInt32(((XmlElement)node).GetElementsByTagName("X")[0].InnerText),
                    Convert.ToInt32(((XmlElement)node).GetElementsByTagName("Y")[0].InnerText));


                bproperty[order].bColor = ((XmlElement)node).GetElementsByTagName("color")[0].InnerText;
                bproperty[order].bID = ((XmlElement)node).GetElementsByTagName("enc")[0].InnerText;
                bproperty[order].pngUP = ((XmlElement)node).GetElementsByTagName("patternup")[0].InnerText;
                bproperty[order].pngDN = ((XmlElement)node).GetElementsByTagName("patterndn")[0].InnerText;
                bevent[order].bDll = ((XmlElement)node).GetElementsByTagName("dllpath")[0].InnerText;
                bevent[order].bNS = ((XmlElement)node).GetElementsByTagName("namespace")[0].InnerText;
                bevent[order].bClass = ((XmlElement)node).GetElementsByTagName("class")[0].InnerText;
                bevent[order].bParameterup = ((XmlElement)node).GetElementsByTagName("parameterup")[0].InnerText;
                bevent[order].bMethodup = ((XmlElement)node).GetElementsByTagName("methodup")[0].InnerText;
                bevent[order].bParameterdn = ((XmlElement)node).GetElementsByTagName("parameterdn")[0].InnerText;
                bevent[order].bMethoddn = ((XmlElement)node).GetElementsByTagName("methoddn")[0].InnerText;
                order++;
            }
            bproperty[order].bName = "error";
            return;
        }


        Color[] ccc = new Color[]{ Color.AliceBlue,Color.AntiqueWhite,Color.Aqua,Color.Aquamarine,
            Color.Azure,Color.Beige,Color.Bisque,Color.Black,Color.BlanchedAlmond,Color.Blue,
            Color.BlueViolet,Color.Brown,Color.BurlyWood,Color.CadetBlue,Color.Chartreuse,Color.Chocolate,
            Color.Coral,Color.CornflowerBlue,Color.Cornsilk,Color.Crimson,Color.Cyan,Color.DarkBlue,
            Color.DarkCyan,Color.DarkGoldenrod,Color.DarkGray,Color.DarkGreen,Color.DarkKhaki,Color.DarkMagenta,
            Color.DarkOliveGreen,Color.DarkOrange,Color.DarkOrchid,Color.DarkRed,Color.DarkSalmon,Color.DarkSeaGreen,
            Color.DarkSlateBlue,Color.DarkSlateGray,Color.DarkTurquoise,Color.DarkViolet,Color.DeepPink,Color.DeepSkyBlue,Color.DimGray,
            Color.DodgerBlue,Color.Empty,Color.Firebrick,Color.FloralWhite,Color.ForestGreen,Color.Fuchsia,Color.Gainsboro,Color.GhostWhite,
            Color.Gold,Color.Goldenrod,Color.Gray,Color.Green,Color.GreenYellow,Color.Honeydew,Color.HotPink,
            Color.IndianRed,Color.Indigo,Color.Ivory,Color.Khaki,Color.Lavender,Color.LavenderBlush,Color.LawnGreen,
            Color.LemonChiffon,Color.LightBlue,Color.LightCoral,Color.LightCyan,Color.LightGoldenrodYellow,Color.LightGray,
            Color.LightGreen,Color.LightPink,Color.LightSalmon,Color.LightSeaGreen,Color.LightSkyBlue,Color.LightSlateGray,Color.LightSteelBlue,
            Color.LightYellow,Color.Lime,Color.LimeGreen,Color.Linen,Color.Magenta,Color.Maroon,Color.MediumAquamarine,Color.MediumBlue,
            Color.MediumOrchid,Color.MediumPurple,Color.MediumSeaGreen,Color.MediumSlateBlue,Color.MediumSpringGreen,Color.MediumTurquoise,Color.MediumVioletRed,
            Color.MidnightBlue,Color.MintCream,Color.MistyRose,Color.Moccasin,Color.NavajoWhite,Color.Navy,
            Color.OldLace,Color.Olive,Color.OliveDrab,Color.Orange,Color.OrangeRed,Color.Orchid,
            Color.PaleGoldenrod,Color.PaleGreen,Color.PaleTurquoise,Color.PaleVioletRed,Color.PapayaWhip,Color.PeachPuff,
            Color.Peru,Color.Pink,Color.Plum,Color.PowderBlue,Color.Purple,Color.Red,Color.RosyBrown,Color.RoyalBlue,Color.SaddleBrown,
            Color.Salmon,Color.SandyBrown,Color.SeaGreen,Color.SeaShell,Color.Sienna,Color.Silver,Color.SkyBlue,
            Color.SlateBlue,Color.SlateGray,Color.Snow,Color.SpringGreen,Color.SteelBlue,Color.Tan,Color.Teal,
            Color.Thistle,Color.Tomato,Color.Transparent,Color.Turquoise,Color.Violet,Color.Wheat,Color.White,Color.WhiteSmoke,
            Color.Yellow,Color.YellowGreen };
        string[] sss = new string[] { "AliceBlue", "AntiqueWhite", "Aqua", "Aquamarine",
            "Azure","Beige","Bisque","Black","BlanchedAlmond","Blue",
            "BlueViolet","Brown","BurlyWood","CadetBlue","Chartreuse","Chocolate",
            "Coral","CornflowerBlue","Cornsilk","Crimson","Cyan","DarkBlue",
            "DarkCyan","DarkGoldenrod","DarkGray","DarkGreen","DarkKhaki","DarkMagenta",
            "DarkOliveGreen","DarkOrange","DarkOrchid","DarkRed","DarkSalmon","DarkSeaGreen",
            "DarkSlateBlue","DarkSlateGray","DarkTurquoise","DarkViolet","DeepPink","DeepSkyBlue","DimGray",
            "DodgerBlue","Empty","Firebrick","FloralWhite","ForestGreen","Fuchsia","Gainsboro","GhostWhite",
            "Gold","Goldenrod","Gray","Green","GreenYellow","Honeydew","HotPink",
            "IndianRed","Indigo","Ivory","Khaki","Lavender","LavenderBlush","LawnGreen",
            "LemonChiffon","LightBlue","LightCoral","LightCyan","LightGoldenrodYellow","LightGray",
            "LightGreen","LightPink","LightSalmon","LightSeaGreen","LightSkyBlue","LightSlateGray","LightSteelBlue",
            "LightYellow","Lime","LimeGreen","Linen","Magenta","Maroon","MediumAquamarine","MediumBlue",
            "MediumOrchid","MediumPurple","MediumSeaGreen","MediumSlateBlue","MediumSpringGreen","MediumTurquoise","MediumVioletRed",
            "MidnightBlue","MintCream","MistyRose","Moccasin","NavajoWhite","Navy",
            "OldLace","Olive","OliveDrab","Orange","OrangeRed","Orchid",
            "PaleGoldenrod","PaleGreen","PaleTurquoise","PaleVioletRed","PapayaWhip","PeachPuff",
            "Peru","Pink","Plum","PowderBlue","Purple","Red","RosyBrown","RoyalBlue","SaddleBrown",
            "Salmon","SandyBrown","SeaGreen","SeaShell","Sienna","Silver","SkyBlue",
            "SlateBlue","SlateGray","Snow","SpringGreen","SteelBlue","Tan","Teal",
            "Thistle","Tomato","Transparent","Turquoise","Violet","Wheat","White","WhiteSmoke",
            "Yellow","YellowGreen" };
        public string getColor(Button btn)
        {
            string str = "null";
            for (int i = 0; i < sss.Length; i++)
            {
                if (btn.BackColor == ccc[i])
                {
                    str = sss[i];
                    break;
                }
            }
            return str;
        }
        public void setColor(Button btn,string color)
        {
            for (int i = 0; i < sss.Length; i++)
            {
                if (color.Equals(sss[i]))
                {
                    btn.BackColor = ccc[i];
                    break;
                }
            }
        }
        public void setCombox(ComboBox abc)
        {
            for (int i = 0; i < sss.Length; i++)
            {
                abc.Items.Add(sss[i]);
            }
                return;
        }
    }

}

4.事件定义示例程序

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;


namespace gxzkevent
{
    public class EventLib
    {
        public void NoParRtn()
        {
            return;
        }
        public string NoPar()
        {
            string str = "2018/03/04";
            return str;
        }
        public void NoRtn(string str)
        {
            return;
        }
        public string gxzk1(string str)
        {
            string rtn;
            rtn = "order:1||" + str;
            return rtn;
        }
        public string gxzk2(string str)
        {
            string rtn;
            rtn = "order:2||" + str;
            return rtn;
        }
        public string gxzk3(string str)
        {
            string rtn;
            rtn = "order:3||" + str;
            return rtn;
        }
        public string gxzk4(string str)
        {
            string rtn;
            rtn = "order:4||" + str;
            return rtn;
        }
    }

}

六、本程序使用注意事项

本程序分为开发和运行两种方式:

1.在开发mode下,可追加和删除按键,设置属性(皮肤和事件定制),可方便移动位置,设置大小,选择皮肤模板,并保存

2.在运行mode下,就是将【2】定制好的按键信息读入、显示,直接进入运行mode,这时就不能更改皮肤和定制信息

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-28
  • 2022-12-23
  • 2021-07-03
  • 2022-12-23
猜你喜欢
  • 2021-12-15
  • 2021-12-04
  • 2021-12-04
  • 2021-08-19
  • 2021-11-26
相关资源
相似解决方案