📄 wndlessbutton.cs
字号:
namespace Imps.Client.Pc.WndlessControls
{
using Imps.Client.Pc;
using System;
using System.Drawing;
using System.Windows.Forms;
public class WndlessButton : WndlessControl
{
private Color _clrBorderLight;
private System.Drawing.Image _image;
public WndlessButton()
{
base.Margin = new Padding(2);
base.BorderColor = Color.FromArgb(200, 0x20, 0x20, 0x20);
this.BorderColorLight = Color.FromArgb(200, 0xba, 0xba, 0xba);
}
protected override void OnPaint(PaintEventArgs e)
{
Rectangle clientRectangle = this.ClientRectangle;
int x = clientRectangle.Left;
int y = clientRectangle.Top;
if (base.MouseDown)
{
DrawHelper.DrawBorder(e.Graphics, base.Bounds, base.BorderColor, this.BorderColorLight, ButtonBorderStyle.Inset);
}
else if (base.MouseHovered)
{
DrawHelper.DrawBorder(e.Graphics, base.Bounds, base.BorderColor, this.BorderColorLight, ButtonBorderStyle.Outset);
}
if (this.Image != null)
{
y = ((clientRectangle.Height - this.Image.Height) / 2) + clientRectangle.Top;
if (base.Enabled)
{
e.Graphics.DrawImage(this.Image, x, y, this.Image.Width, this.Image.Height);
}
else
{
ControlPaint.DrawImageDisabled(e.Graphics, this.Image, x, y, base.BackColor);
}
clientRectangle = new Rectangle(clientRectangle.Left + this.Image.Width, clientRectangle.Top, clientRectangle.Width - this.Image.Width, clientRectangle.Height);
}
if (this.Text.Length > 0)
{
TextFormatFlags flags = 0x8004;
if (base.Enabled)
{
TextRenderer.DrawText((IDeviceContext) e.Graphics, this.Text, base.Font, clientRectangle, base.ForeColor, flags);
}
else
{
TextRenderer.DrawText((IDeviceContext) e.Graphics, this.Text, base.Font, clientRectangle, Color.FromArgb(200, 200, 200), flags);
}
}
}
public Color BorderColorLight
{
get
{
return this._clrBorderLight;
}
set
{
this._clrBorderLight = value;
}
}
protected override bool DoInvalidateWhenHover
{
get
{
return true;
}
}
public System.Drawing.Image Image
{
get
{
return this._image;
}
set
{
if (this._image != value)
{
this._image = value;
if (base.AutoSize)
{
base.DoAutoSize(false);
}
base.Invalidate();
}
}
}
public override Size PreferredClientSize
{
get
{
Size size = (this.Image != null) ? this.Image.Size : Size.Empty;
Size size2 = string.IsNullOrEmpty(this.Text) ? Size.Empty : TextRenderer.MeasureText(this.Text, base.Font);
int width = size.Width + size2.Width;
int height = size.Height;
if (height < size2.Height)
{
height = size2.Height;
}
return new Size(width, height);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -