using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using DevComponents.DotNetBar; namespace POSV.Component { public class TouchLabelExt : LabelX { public event EventHandler TouchClick; public TouchLabelExt() { this.SetStyle(ControlStyles.UserPaint , true); this.SetStyle(ControlStyles.AllPaintingInWmPaint , true); this.SetStyle(ControlStyles.Opaque , true); this.SetStyle(ControlStyles.ResizeRedraw , true); this.SetStyle(ControlStyles.StandardDoubleClick , true); this.SetStyle(ControlStyles.DoubleBuffer , true); this.SetStyle(ControlStyles.SupportsTransparentBackColor , true); } protected virtual void OnTouchClick(EventArgs e) { TouchClick?.Invoke(this , e); } protected override void WndProc(ref Message m) { switch (m.Msg) { case Win32.WM_POINTERDOWN: case Win32.WM_POINTERUP: case Win32.WM_POINTERUPDATE: case Win32.WM_POINTERCAPTURECHANGED: break; default: base.WndProc(ref m); return; } int pointerId = Win32.GET_POINTER_ID(m.WParam); Win32.POINTER_INFO pi = new Win32.POINTER_INFO(); if (!Win32.GetPointerInfo(pointerId , ref pi)) { Win32.CheckLastError(); } Point pt = PointToClient(pi.PtPixelLocation.ToPoint()); MouseEventArgs me = new MouseEventArgs(System.Windows.Forms.MouseButtons.Left , 1 , pt.X , pt.Y , 0); switch (m.Msg) { case Win32.WM_POINTERDOWN: OnMouseDown(me); break; case Win32.WM_POINTERUP: OnMouseUp(me); break; case Win32.WM_POINTERUPDATE: //Console.WriteLine("UPDATE"); break; } } private Color _backColor1 = Color.Transparent; public Color BackColor1 { get { return this._backColor1; } set { this._backColor1 = value; this.BackColor = this._backColor1; } } private Color _backColor2 = Color.Tan; public Color BackColor2 { get { return this._backColor2; } set { this._backColor2 = value; } } protected override void OnMouseDown(MouseEventArgs e) { if (e.Button == MouseButtons.Left) { this.BackColor = this._backColor2; } } protected override void OnMouseUp(MouseEventArgs e) { if (e.Button == MouseButtons.Left) { this.BackColor = this._backColor1; this.OnTouchClick(e); } } } }