📄 xcontrolbase.cs
字号:
namespace Imps.Client.Pc.Controls
{
using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
public class XControlBase : Control
{
private Color _borderColor = Color.Black;
private System.Windows.Forms.BorderStyle _borderStyle;
private System.Windows.Forms.ButtonBorderStyle _buttonBorderStyle = System.Windows.Forms.ButtonBorderStyle.Solid;
private bool _isMouseOver;
private Control _parentControl;
private Rectangle preRec = Rectangle.Empty;
public XControlBase()
{
base.SetStyle(0x20802, true);
}
protected virtual void AdjustSize()
{
}
public void Invalidate()
{
if (this._parentControl != null)
{
this._parentControl.Invalidate(Rectangle.Union(base.Bounds, this.preRec));
}
else
{
base.Invalidate();
}
}
protected override void OnMouseLeave(EventArgs e)
{
this._isMouseOver = false;
this.Parent.Cursor = Cursors.Default;
base.OnMouseLeave(e);
}
protected override void OnMouseMove(MouseEventArgs e)
{
this._isMouseOver = true;
this.Parent.Cursor = this.Cursor;
base.OnMouseMove(e);
}
protected override void OnPaddingChanged(EventArgs e)
{
base.OnPaddingChanged(e);
this.Invalidate();
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
this.OnPaintControl(new PaintEventArgs(e.Graphics, base.ClientRectangle));
}
protected override void OnPaintBackground(PaintEventArgs e)
{
base.OnPaintBackground(e);
if ((this.BackColor != Color.Transparent) && (this.BackColor != SystemColors.Control))
{
e.Graphics.FillRectangle(new SolidBrush(this.BackColor), e.ClipRectangle);
}
}
protected virtual void OnPaintControl(PaintEventArgs e)
{
this.preRec = base.Bounds;
this.OnPaintBackground(e);
if (this.BorderStyle != System.Windows.Forms.BorderStyle.None)
{
if (this.BorderStyle == System.Windows.Forms.BorderStyle.Fixed3D)
{
ControlPaint.DrawBorder3D(e.Graphics, e.ClipRectangle);
}
else if (this.BorderStyle == System.Windows.Forms.BorderStyle.FixedSingle)
{
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, this.BorderColor, this.ButtonBorderStyle);
}
}
}
protected virtual void OnPaintParentControl(PaintEventArgs e)
{
if (base.Visible)
{
this.OnPaintControl(new PaintEventArgs(e.Graphics, base.Bounds));
}
}
protected override void OnParentChanged(EventArgs e)
{
if (base.Parent != null)
{
this._parentControl = base.Parent;
base.Parent.Click += new EventHandler(this.Parent_Click);
base.Parent.add_MouseClick(new MouseEventHandler(this.Parent_MouseClick));
base.Parent.MouseLeave += new EventHandler(this.Parent_MouseLeave);
base.Parent.MouseMove += new MouseEventHandler(this.Parent_MouseMove);
base.Parent.DoubleClick += new EventHandler(this.Parent_DoubleClick);
base.Parent.add_MouseDoubleClick(new MouseEventHandler(this.Parent_MouseDoubleClick));
base.Parent.MouseHover += new EventHandler(this.Parent_MouseHover);
base.Parent.MouseUp += new MouseEventHandler(this.Parent_MouseUp);
base.Parent.MouseDown += new MouseEventHandler(this.Parent_MouseDown);
base.Parent.Paint += new PaintEventHandler(this.Parent_Paint);
base.Parent.HandleCreated += new EventHandler(this.Parent_HandleCreated);
base.Parent.Controls.Remove(this);
}
}
protected override void OnVisibleChanged(EventArgs e)
{
base.OnVisibleChanged(e);
this.Invalidate();
}
private void Parent_Click(object sender, EventArgs e)
{
if (XControlHelper.IsMouseOnControl(this, sender as Control))
{
this.OnClick(e);
}
}
private void Parent_DoubleClick(object sender, EventArgs e)
{
if (XControlHelper.IsMouseOnControl(this, sender as Control))
{
this.OnDoubleClick(e);
}
}
private void Parent_HandleCreated(object sender, EventArgs e)
{
this.AdjustSize();
}
private void Parent_MouseClick(object sender, MouseEventArgs e)
{
if (XControlHelper.IsMouseOnControl(this, sender as Control))
{
this.OnMouseClick(e);
}
}
private void Parent_MouseDoubleClick(object sender, MouseEventArgs e)
{
if (XControlHelper.IsMouseOnControl(this, sender as Control))
{
this.OnMouseDoubleClick(e);
}
}
private void Parent_MouseDown(object sender, MouseEventArgs e)
{
if (XControlHelper.IsMouseOnControl(this, sender as Control))
{
this.OnMouseDown(e);
}
}
private void Parent_MouseHover(object sender, EventArgs e)
{
if (XControlHelper.IsMouseOnControl(this, sender as Control))
{
this.OnMouseHover(e);
}
}
private void Parent_MouseLeave(object sender, EventArgs e)
{
if (XControlHelper.IsMouseOnControl(this, sender as Control) && this._isMouseOver)
{
this.OnMouseLeave(e);
}
}
private void Parent_MouseMove(object sender, MouseEventArgs e)
{
if (XControlHelper.IsMouseOnControl(this, sender as Control))
{
this.OnMouseMove(e);
}
else if (this._isMouseOver)
{
this.OnMouseLeave(e);
}
}
private void Parent_MouseUp(object sender, MouseEventArgs e)
{
if (XControlHelper.IsMouseOnControl(this, sender as Control))
{
this.OnMouseUp(e);
}
}
private void Parent_Paint(object sender, PaintEventArgs e)
{
if (e.ClipRectangle.IntersectsWith(base.Bounds))
{
this.OnPaintParentControl(e);
}
}
[Category("外观"), Description("标签的边框颜色,当BorderStyle设置为FixedSingle时有效")]
public Color BorderColor
{
get
{
return this._borderColor;
}
set
{
if (this._borderColor != value)
{
this._borderColor = value;
this.Invalidate();
}
}
}
[DefaultValue(0), Category("外观"), Description("标签的边框样式")]
public virtual System.Windows.Forms.BorderStyle BorderStyle
{
get
{
return this._borderStyle;
}
set
{
if (this._borderStyle != value)
{
this._borderStyle = value;
this.Invalidate();
}
}
}
[Description("标签的边框样式,当BorderStyle设置为FixedSingle时有效"), Category("外观")]
public System.Windows.Forms.ButtonBorderStyle ButtonBorderStyle
{
get
{
return this._buttonBorderStyle;
}
set
{
if (this._buttonBorderStyle != value)
{
this._buttonBorderStyle = value;
this.Invalidate();
}
}
}
internal bool IsMouseOver
{
get
{
return this._isMouseOver;
}
}
public Control Parent
{
get
{
if (this._parentControl != null)
{
return this._parentControl;
}
return base.Parent;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -