using DevComponents.DotNetBar; using System; using System.Drawing; using System.Windows.Forms; using System.ComponentModel; namespace JwKdsV.Component { public class TouchLabelX : LabelX { public delegate void EventHandler(object sender, EventArgs e); public event EventHandler TouchClick; public TouchLabelX() { this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | 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 Font _font = new Font("宋体", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); public new Font Font { get { return _font; } set { base.Font = value; base.BackgroundStyle.Font = value; _font = value; this.Invalidate(); } } private eStyleTextAlignment _textAlignment = eStyleTextAlignment.Center; public new eStyleTextAlignment TextAlignment { get { return this._textAlignment; } set { this._textAlignment = value; this.BackgroundStyle.TextAlignment = this._textAlignment; this.Invalidate(true); } } private eStyleTextAlignment _textLineAlignment = eStyleTextAlignment.Center; public new eStyleTextAlignment TextLineAlignment { get { return this._textLineAlignment; } set { this._textLineAlignment = value; this.BackgroundStyle.TextLineAlignment = this._textLineAlignment; this.Invalidate(true); } } 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); //var rect = this.RectangleToScreen(this.ClientRectangle); //if (rect.Contains(Control.MousePosition)) //{ // this.OnTouchClick(e); //} } } } }