📄 xformwndlesscontrol.cs
字号:
namespace Imps.Client.Pc.BizControls
{
using Imps.Client.Pc;
using System;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
public class XFormWndlessControl : IDisposable
{
private Size _clientSize;
private int _handle;
private FormDirection _hitTestCode = FormDirection.NoDragMove;
private System.Drawing.Point _location;
protected ContextMenuStrip _menustrip;
private string _name;
private bool _NonClientArea;
private System.Windows.Forms.Padding _padding = System.Windows.Forms.Padding.Empty;
protected Control _parent;
private object _tag;
private string _toolTipText = string.Empty;
private bool _visible = true;
public static int WNDLESSCONTROL_INVALIDATE = 0x123;
public event EventHandler Click;
public event EventHandler DoubleClick;
public bool CanAttachClick()
{
return (this.Click == null);
}
public virtual void Dispose()
{
}
public void Invalidate()
{
if (!this._NonClientArea)
{
System.Drawing.Rectangle rc = new System.Drawing.Rectangle(this._location, this._clientSize);
if ((rc.Width == 0) || (rc.Height == 0))
{
rc.Width += 10;
rc.Height += 10;
this._parent.Invalidate(rc);
}
else
{
this._parent.Invalidate(rc);
}
}
else
{
IntPtr hdc = InnerWin32.GetWindowDC(this._parent.Handle);
using (Graphics g = Graphics.FromHdc(hdc))
{
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(this._location, this._clientSize);
Region region = new Region(rect);
InnerWin32.SendMessage(this._parent.Handle, 0x85, (int) region.GetHrgn(g), WNDLESSCONTROL_INVALIDATE);
}
InnerWin32.ReleaseDC(this._parent.Handle, hdc);
}
}
public virtual bool MouseClick(EventArgs e)
{
return false;
}
public virtual void MouseDblClick(EventArgs e)
{
}
public virtual bool NcMouseClick(EventArgs e)
{
return false;
}
public virtual bool NcMouseDblClick(Graphics g, System.Drawing.Point pt)
{
return false;
}
public virtual bool OnMouseDown(MouseEventArgs e)
{
return false;
}
public virtual void OnMouseLeave(EventArgs e)
{
}
public virtual bool OnMouseMove(MouseEventArgs e)
{
return false;
}
public virtual bool OnMouseUp(MouseEventArgs e)
{
return false;
}
public virtual bool OnNcMouseDown(Graphics g, System.Drawing.Point pt, MouseButtons button)
{
return false;
}
public virtual void OnNcMouseLeave(EventArgs e)
{
}
public virtual bool OnNcMouseMove(Graphics g, System.Drawing.Point pt)
{
return false;
}
public virtual bool OnNcMouseUp(Graphics g, System.Drawing.Point pt, MouseButtons button)
{
return false;
}
public virtual void OnNcPaint(Graphics g, System.Drawing.Rectangle clipRectangle)
{
}
public virtual void OnPaint(Graphics g, System.Drawing.Rectangle clipRectangle)
{
}
internal void RaiseClick(object sender, EventArgs e)
{
if (this.Click != null)
{
this.Click(sender, e);
}
}
internal bool RaiseDoubleClick(object sender, EventArgs e)
{
if (this.DoubleClick != null)
{
this.DoubleClick(sender, e);
return true;
}
return false;
}
public int Bottom
{
get
{
return (this._location.Y + this._clientSize.Height);
}
}
public Size ClientSize
{
get
{
return this._clientSize;
}
set
{
this._clientSize = value;
}
}
public int Handle
{
get
{
return this._handle;
}
internal set
{
this._handle = value;
}
}
public int Height
{
get
{
return this._clientSize.Height;
}
}
public FormDirection HitTestCode
{
get
{
return this._hitTestCode;
}
set
{
this._hitTestCode = value;
}
}
public int Left
{
get
{
return this._location.X;
}
}
public System.Drawing.Point Location
{
get
{
return this._location;
}
set
{
this._location = value;
}
}
public ContextMenuStrip MenuStrip
{
get
{
return this._menustrip;
}
set
{
this._menustrip = value;
}
}
public string Name
{
get
{
return this._name;
}
set
{
this._name = value;
}
}
public bool NonClientArea
{
get
{
return this._NonClientArea;
}
set
{
this._NonClientArea = value;
}
}
public System.Windows.Forms.Padding Padding
{
get
{
return this._padding;
}
set
{
this._padding = value;
}
}
public Control Parent
{
get
{
return this._parent;
}
internal set
{
this._parent = value;
}
}
public System.Drawing.Rectangle Rectangle
{
get
{
if ((this._clientSize.Width != 0) && (this._clientSize.Height != 0))
{
return new System.Drawing.Rectangle(this._location, this._clientSize);
}
return new System.Drawing.Rectangle(this._location, new Size(10, 10));
}
}
public int Right
{
get
{
return (this._location.X + this._clientSize.Width);
}
}
public object Tag
{
get
{
return this._tag;
}
set
{
this._tag = value;
}
}
public string ToolTipText
{
get
{
return this._toolTipText;
}
set
{
this._toolTipText = value;
}
}
public int Top
{
get
{
return this._location.Y;
}
}
public bool Visible
{
get
{
return this._visible;
}
set
{
bool flag = this._visible;
this._visible = value;
if (((flag != value) && (this._parent != null)) && this._parent.IsHandleCreated)
{
this.Invalidate();
}
}
}
public int Width
{
get
{
return this._clientSize.Width;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -