You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

527 lines
15 KiB
C#

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using DevComponents.DotNetBar;
using System.Windows.Forms;
using DevComponents.DotNetBar.Controls;
namespace JwKdsV.Component
{
public class TouchButtonX2 : DoubleBufferPanelX
{
private const string LOCK_NAME = "__icon__";
private const string NOTIFY_NAME = "__notify__";
private FlyoutX flyout = null;
public TouchButtonX2()
{
this.SetStyle(ControlStyles.DoubleBuffer | ControlStyles.OptimizedDoubleBuffer | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
LabelX icon = new LabelX();
icon.Name = LOCK_NAME;
icon.Location = new Point(1, 1);
icon.Size = this._size;
icon.Symbol = "\uf023";
icon.SymbolSet = eSymbolSet.Awesome;
icon.SymbolSize = this._symbolSize;
icon.SymbolColor = this._symbolColor;
icon.Visible = this._lock;
this.Controls.Add(icon);
LabelX notify = new LabelX();
notify.Name = NOTIFY_NAME;
notify.Size = _notifySize;
notify.Location = new Point(this.Width - _notifySize.Width - 3, 3);
notify.BackColor = _notifyColor;
notify.TextAlignment = StringAlignment.Center;
notify.TextLineAlignment = StringAlignment.Center;
notify.Text = "99+";
notify.ForeColor = Color.White;
notify.Font = new Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134)));
this.Controls.Add(notify);
this.Style.BackColor1.Color = this._backColor1;
this.Style.BackColor2.Color = this._backColor1;
this.Enabled = !this._lock;
this.Cursor = Cursors.Hand;
}
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(MouseButtons.Left, 1, pt.X, pt.Y, 0);
switch (m.Msg)
{
case Win32.WM_POINTERDOWN:
//Console.WriteLine("TOCOU" + pt);
this.OnMouseDown(me);
break;
case Win32.WM_POINTERUP:
//Console.WriteLine("LEVANTOU");
this.OnMouseUp(me);
break;
case Win32.WM_POINTERUPDATE:
//Console.WriteLine("UPDATE");
break;
}
}
public delegate void EventHandler(object sender, TouchEventArgs e);
public event EventHandler TouchClick;
public event EventHandler TouchBeforeClick;
protected virtual void OnTouchClick(TouchEventArgs e)
{
TouchClick?.Invoke(this, e);
}
protected virtual void OnTouchBeforeClick(TouchEventArgs e)
{
TouchBeforeClick?.Invoke(this, e);
}
private bool _enableFlyout = false;
public bool EnableFlyout
{
get { return this._enableFlyout; }
set
{
this._enableFlyout = value;
if (this._enableFlyout)
{
this.flyout = new FlyoutX();
this.flyout.DisplayMode = eFlyoutDisplayMode.Manual;
this.flyout.PointerSide = this._flyoutSide;
this.flyout.TargetControl = this;
this.flyout.CloseMode = eFlyoutCloseMode.Manual | eFlyoutCloseMode.ClickOutside | eFlyoutCloseMode.ParentFormDeactivate | eFlyoutCloseMode.TargetControlLostFocus;
this.flyout.BackColor = Color.Tan;
this.flyout.DeepIntegration = true;
this.flyout.TopMost = true;
this.flyout.DropShadow = true;
this.flyout.FlyoutShowing += _FlyoutShowing;
this.flyout.FlyoutClosing += _FlyoutClosing;
}
else
{
if (this._flyoutContent != null)
{
this.flyout.Dispose();
this.flyout = null;
}
}
}
}
public event EventHandler FlyoutClosing;
protected virtual void OnFlyoutClosing(TouchEventArgs e)
{
FlyoutClosing?.Invoke(this, e);
}
private void _FlyoutClosing(object sender, FormClosingEventArgs e)
{
this.OnFlyoutClosing(new TouchEventArgs(this.KeyCode));
}
public event EventHandler FlyoutShowing;
protected virtual void OnFlyoutShowing(TouchEventArgs e)
{
FlyoutShowing?.Invoke(this, e);
}
private void _FlyoutShowing(object sender, FlyoutShowingEventArgs e)
{
this.OnFlyoutShowing(new TouchEventArgs(this.KeyCode));
}
public void ShowFlyout()
{
if (this._enableFlyout && this._flyoutContent != null)
{
this.flyout.Show();
}
}
public void ShowFlyout(object targetItem)
{
if (this._enableFlyout && this._flyoutContent != null)
{
this.flyout.Show(targetItem);
}
}
public void ShowFlyout(Rectangle screenFlyoutBounds)
{
if (this._enableFlyout && this._flyoutContent != null)
{
this.flyout.Show(screenFlyoutBounds);
}
}
public void ShowFlyout(Rectangle screenFlyoutBounds, ePointerSide pointerSide, int pointerOffset, object targetItem)
{
if (this._enableFlyout && this._flyoutContent != null)
{
this.flyout.Show(screenFlyoutBounds, pointerSide, pointerOffset, targetItem);
}
}
public void CloseFlyout()
{
if (this._enableFlyout && this._flyoutContent != null)
{
this.flyout.Close();
}
}
private ePointerSide _flyoutSide = ePointerSide.Left;
public ePointerSide FlyoutSide
{
get { return this._flyoutSide; }
set
{
this._flyoutSide = value;
if (this._enableFlyout)
{
this.flyout.PointerSide = this._flyoutSide;
}
}
}
private Control _flyoutContent = null;
public Control FlyoutContent
{
get { return this._flyoutContent; }
set
{
this._flyoutContent = value;
if (this._enableFlyout && this._flyoutContent != null)
{
this.flyout.Content = this._flyoutContent;
}
}
}
private string _keyCode = "";
public string KeyCode
{
get { return this._keyCode; }
set { this._keyCode = value; }
}
private string _permissionCode = "";
/// <summary>
/// 权限控制码
/// </summary>
public string PermissionCode
{
get { return this._permissionCode; }
set { this._permissionCode = value; }
}
private Color _backColor1 = Color.Moccasin;
public Color BackColor1
{
get { return this._backColor1; }
set
{
this._backColor1 = value;
this.Style.BackColor1.Color = this.Style.BackColor2.Color = this.BackColor1;
}
}
private Color _backColor2 = Color.Tan;
public Color BackColor2
{
get { return this._backColor2; }
set
{
this._backColor2 = value;
}
}
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.Style.Font = value;
_font = value;
this.Invalidate();
}
}
private bool _lock = false;
public bool Lock
{
get { return _lock; }
set
{
_lock = value;
Control[] ctrls = this.Controls.Find(LOCK_NAME, false);
if (ctrls.Length == 1)
{
LabelX icon = (LabelX)ctrls[0];
icon.Visible = _lock;
}
this.Enabled = !_lock;
this.Invalidate();
}
}
private Size _size = new Size(26, 26);
public Size LockSize
{
get { return _size; }
set
{
_size = value;
Control[] ctrls = this.Controls.Find(LOCK_NAME, false);
if (ctrls.Length == 1)
{
LabelX icon = (LabelX)ctrls[0];
icon.Size = _size;
}
this.Invalidate();
}
}
private float _symbolSize = 0;
public float SymbolSize
{
get { return _symbolSize; }
set
{
_symbolSize = value;
Control[] ctrls = this.Controls.Find(LOCK_NAME, false);
if (ctrls.Length == 1)
{
LabelX icon = (LabelX)ctrls[0];
icon.SymbolSize = _symbolSize;
}
this.Invalidate();
}
}
private Color _symbolColor = SystemColors.ControlDarkDark;
public Color SymbolColor
{
get { return _symbolColor; }
set
{
_symbolColor = value;
Control[] ctrls = this.Controls.Find(LOCK_NAME, false);
if (ctrls.Length == 1)
{
LabelX icon = (LabelX)ctrls[0];
icon.SymbolColor = _symbolColor;
}
this.Invalidate();
}
}
private bool _notify = false;
public bool Notify
{
get { return _notify; }
set
{
_notify = value;
Control[] ctrls = this.Controls.Find(NOTIFY_NAME, false);
if (ctrls.Length == 1)
{
LabelX notify = (LabelX)ctrls[0];
notify.Visible = _notify;
notify.Location = new Point(this.Width - _notifySize.Width - 3, 3);
notify.Size = _notifySize;
notify.Text = _notifyText;
}
this.Invalidate();
}
}
private Size _notifySize = new Size(30, 16);
public Size NotifySize
{
get { return _notifySize; }
set
{
_notifySize = value;
Control[] ctrls = this.Controls.Find(NOTIFY_NAME, false);
if (ctrls.Length == 1)
{
LabelX notify = (LabelX)ctrls[0];
notify.Location = new Point(this.Width - _notifySize.Width - 3, 3);
notify.Size = _notifySize;
notify.Text = _notifyText;
}
this.Invalidate();
}
}
public string _notifyText = "99+";
public string NotifyText
{
get { return _notifyText; }
set
{
_notifyText = value;
Control[] ctrls = this.Controls.Find(NOTIFY_NAME, false);
if (ctrls.Length == 1)
{
LabelX notify = (LabelX)ctrls[0];
notify.Text = _notifyText;
notify.Location = new Point(this.Width - _notifySize.Width - 3, 3);
notify.Size = _notifySize;
}
this.Invalidate();
}
}
private Color _notifyColor = Color.Red;
public Color NotifyColor
{
get { return _notifyColor; }
set
{
_notifyColor = value;
Control[] ctrls = this.Controls.Find(NOTIFY_NAME, false);
if (ctrls.Length == 1)
{
LabelX notify = (LabelX)ctrls[0];
notify.BackColor = _notifyColor;
}
this.Invalidate();
}
}
protected override void OnMouseDown(MouseEventArgs e)
{
if (this._lock)
{
return;
}
if (e.Button == MouseButtons.Left)
{
this.Style.BackColor1.Color = this.Style.BackColor2.Color = this.BackColor2;
this.OnTouchBeforeClick(new TouchEventArgs(this.KeyCode));
}
}
protected override void OnResize(EventArgs e)
{
base.OnResize(e);
if (_notify)
{
Control[] ctrls = this.Controls.Find(NOTIFY_NAME, false);
if (ctrls.Length == 1)
{
LabelX notify = (LabelX)ctrls[0];
notify.Text = _notifyText;
notify.Location = new Point(this.Width - _notifySize.Width - 3, 3);
notify.Size = _notifySize;
notify.Invalidate();
}
}
}
protected override void OnMouseUp(MouseEventArgs e)
{
if (this._lock)
{
return;
}
if (e.Button == MouseButtons.Left)
{
this.Style.BackColor1.Color = this.Style.BackColor2.Color = this.BackColor1;
this.OnTouchClick(new TouchEventArgs(this.KeyCode));
}
}
}
public class TouchEventArgs : EventArgs
{
private readonly string _value;
public TouchEventArgs(string value)
{
this._value = value;
}
public string Value
{
get
{
return this._value;
}
}
}
}