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

一、目的

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

二、基本功能

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

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

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

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

三、界面

1.主页面


2.属性定义页面


3.其他页面

模板定义页面


事件定义页面


四、功能

1.按键追加:click【ADD】


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

五、代码


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:
           

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值