📄 wndlesscontrolmanager.cs
字号:
namespace Imps.Client.Pc.BizControls
{
using System;
using System.Drawing;
using System.Windows.Forms;
public class WndlessControlManager
{
private WndlessControls _controls;
private Point _location;
private FormEx _parent;
private ToolTip _tip;
public WndlessControlManager(FormEx parent)
{
this._parent = parent;
this._controls = new WndlessControls();
this._controls.ControlAdded += new ControlHandler(this._controls_ControlAdded);
this._tip = new ToolTip();
}
private void _controls_ControlAdded(int index)
{
XFormWndlessControl control = this._controls[index];
control.Parent = this._parent;
}
public void Dispose()
{
foreach (XFormWndlessControl control in this._controls)
{
control.Dispose();
}
if (this._tip != null)
{
this._tip.Dispose();
}
}
public XFormWndlessControl GetControlAt(Point pt, bool nonClient)
{
return this.GetControlAt(pt, false, nonClient);
}
public XFormWndlessControl GetControlAt(Point pt, bool adjusted, bool nonClient)
{
foreach (XFormWndlessControl control in this._controls)
{
bool flag = adjusted;
if ((!nonClient && !control.NonClientArea) && control.Visible)
{
flag = true;
}
if (!nonClient || control.NonClientArea)
{
if (nonClient)
{
if (this.PointInNcRect(pt, control.Rectangle, control.NonClientArea))
{
return control;
}
continue;
}
if (this.PointInRect(pt, control.Rectangle, flag) && (nonClient || !control.NonClientArea))
{
return control;
}
}
}
return null;
}
public FormDirection GetPoint(Point pt, bool nonClient)
{
XFormWndlessControl controlAt = this.GetControlAt(pt, nonClient);
if (controlAt == null)
{
return FormDirection.None;
}
if (controlAt is XFormWndlessLabel)
{
return ((XFormWndlessLabel) controlAt).UrlHitTest(pt);
}
return controlAt.HitTestCode;
}
private void HideTip()
{
this._tip.Active = false;
}
public bool MouseClick(EventArgs e)
{
Point pt = Point.Empty;
ChatEditCtrlManager.GetCursorPos(ref pt);
Point point2 = this._parent.PointToClient(pt);
foreach (XFormWndlessControl control in this._controls)
{
if (!control.Visible || control.NonClientArea)
{
continue;
}
WndlessBoxButton button = control as WndlessBoxButton;
if (button != null)
{
if (this.PointInRect(point2, control.Rectangle))
{
button.State = BoxButtonState.Hover;
this.ShowTip(button, false);
this._parent.Invalidate(button.Rectangle);
button.RaiseClick(this._parent, e);
return true;
}
continue;
}
if (this.PointInRect(point2, control.Rectangle))
{
return control.MouseClick(e);
}
}
return false;
}
public bool MouseDblClick(EventArgs e)
{
Point pt = Point.Empty;
MouseEventArgs args = e as MouseEventArgs;
if (args == null)
{
ChatEditCtrlManager.GetCursorPos(ref pt);
pt = this._parent.PointToClient(pt);
}
else
{
pt = new Point(args.X, args.Y);
}
foreach (XFormWndlessControl control in this._controls)
{
if (this.PointInRect(pt, control.Rectangle) && !control.NonClientArea)
{
control.MouseDblClick(e);
return true;
}
}
return false;
}
public bool MouseDown(MouseEventArgs e)
{
Point pt = new Point(e.X, e.Y);
XFormWndlessControl button = this.GetControlAt(pt, false);
if (button != null)
{
if (button is WndlessBoxButton)
{
if (button.OnMouseDown(e))
{
return true;
}
this.ShowTip(button, false);
}
else
{
button.OnMouseDown(e);
}
}
return false;
}
public void MouseLeave(EventArgs e)
{
foreach (XFormWndlessControl control in this._controls)
{
WndlessBoxButton button = control as WndlessBoxButton;
if (button != null)
{
if (control.HitTestCode != FormDirection.None)
{
button.State = BoxButtonState.Normal;
button.Invalidate();
}
continue;
}
control.OnMouseLeave(e);
}
this.HideTip();
}
public bool MouseMove(MouseEventArgs e)
{
foreach (XFormWndlessControl control in this._controls)
{
if (!control.Visible || control.NonClientArea)
{
continue;
}
WndlessBoxButton button = control as WndlessBoxButton;
if (button != null)
{
if (!this.PointInRect(new Point(e.X, e.Y), control.Rectangle))
{
if (button.State != BoxButtonState.Normal)
{
button.State = BoxButtonState.Normal;
this._parent.Invalidate(button.Rectangle);
return true;
}
}
else if (button.State != BoxButtonState.Hover)
{
if (!button.NonClientArea)
{
this.ShowTip(button);
}
button.State = BoxButtonState.Hover;
this._parent.Invalidate(button.Rectangle);
return true;
}
continue;
}
if (this.PointInRect(new Point(e.X, e.Y), control.Rectangle))
{
return control.OnMouseMove(e);
}
}
return false;
}
public bool MouseUp(MouseEventArgs e)
{
XFormWndlessControl control = this.GetControlAt(new Point(e.X, e.Y), true, false);
return (((control != null) && control.OnMouseUp(e)) || true);
}
public bool NcMouseDbClick(Graphics g, Point pt, MouseButtons button, bool bNonClient)
{
XFormWndlessControl control = this.GetControlAt(pt, true, bNonClient);
return ((control != null) && control.NcMouseDblClick(g, pt));
}
public bool NcMouseDown(Graphics g, Point pt, MouseButtons button, bool bNonClient)
{
XFormWndlessControl control = this.GetControlAt(pt, true, bNonClient);
return (((control != null) && control.OnNcMouseDown(g, pt, button)) || true);
}
public bool NcMouseLeave()
{
foreach (XFormWndlessControl control in this._controls)
{
WndlessBoxButton button = control as WndlessBoxButton;
if (button != null)
{
if (control.HitTestCode != FormDirection.None)
{
button.State = BoxButtonState.Normal;
button.Invalidate();
}
continue;
}
EventArgs e = new EventArgs();
control.OnMouseLeave(e);
}
return true;
}
public bool NcMouseMove(Graphics g, Point pt)
{
foreach (XFormWndlessControl control in this._controls)
{
WndlessBoxButton button = control as WndlessBoxButton;
if (button != null)
{
if (!this.PointInNcRect(pt, control.Rectangle, control.NonClientArea))
{
if (button.State != BoxButtonState.Normal)
{
button.State = BoxButtonState.Normal;
button.Invalidate();
return false;
}
}
else if (button.State == BoxButtonState.Normal)
{
BoxButtonState state = button.State;
button.State = BoxButtonState.Hover;
if (state != button.State)
{
button.Invalidate();
}
return false;
}
continue;
}
if (this.PointInNcRect(pt, control.Rectangle, control.NonClientArea))
{
control.OnNcMouseMove(g, pt);
}
}
return true;
}
public bool NcMouseUp(Graphics g, Point pt, MouseButtons button, bool bNonClient)
{
XFormWndlessControl control = this.GetControlAt(pt, true, bNonClient);
return (((control != null) && control.OnNcMouseUp(g, pt, button)) || true);
}
public void OnNcPaint(Graphics g, Rectangle clipRectangle)
{
foreach (XFormWndlessControl control in this._controls)
{
control.OnNcPaint(g, clipRectangle);
}
}
public void OnPaint(Graphics g, Rectangle clipRectangle)
{
foreach (XFormWndlessControl control in this._controls)
{
control.OnPaint(g, clipRectangle);
}
}
public bool PointInNcRect(Point pt, Rectangle rect, bool nonClient)
{
if (nonClient)
{
pt.X += 2;
pt.Y += 4;
pt.X -= SystemInformation.WorkingArea.Left;
pt.Y -= SystemInformation.WorkingArea.Top;
}
return this.PointInRect(pt, rect);
}
public bool PointInRect(Point pt, Rectangle rect)
{
return (((pt.X >= rect.Left) && (pt.X <= rect.Right)) && ((pt.Y >= rect.Top) && (pt.Y <= rect.Bottom)));
}
public bool PointInRect(Point pt, Rectangle rect, bool adjusted)
{
if (!adjusted)
{
rect.X += this._location.X;
rect.Y += this._location.Y;
}
return this.PointInRect(pt, rect);
}
private void ShowTip(WndlessBoxButton button)
{
this.ShowTip(button, true);
}
private void ShowTip(XFormWndlessControl button, bool bShowTip)
{
foreach (XFormWndlessControl control in this._controls)
{
WndlessBoxButton button2 = control as WndlessBoxButton;
if (button.Equals(button2) && bShowTip)
{
this._tip.Active = true;
this._tip.SetToolTip(this._parent, button.ToolTipText);
}
}
}
public WndlessControls Controls
{
get
{
return this._controls;
}
}
public Point Location
{
get
{
return this._location;
}
set
{
this._location = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -