📄 wndlesslinklabel.cs
字号:
namespace Imps.Client.Pc.WndlessControls
{
using System;
using System.Drawing;
using System.Windows.Forms;
public class WndlessLinkLabel : WndlessLabel
{
private Font _hoverFont;
private System.Windows.Forms.LinkBehavior _linkBehavior;
private Font _linkFont;
public WndlessLinkLabel()
{
base.ForeColor = Color.Blue;
this.LinkBehavior = System.Windows.Forms.LinkBehavior.HoverUnderline;
base.Cursor = Cursors.Hand;
}
public override void Dispose()
{
this.InnerDisposeFonts();
base.Dispose();
}
private void InnerDisposeFonts()
{
if ((this._hoverFont != null) && (this._hoverFont != this._linkFont))
{
this._hoverFont.Dispose();
}
if ((this._linkFont != null) && (this._linkFont != base.Font))
{
this._linkFont.Dispose();
}
}
protected override void OnPaint(PaintEventArgs e)
{
if (this.Text.Length > 0)
{
TextFormatFlags textFormat = base.TextFormat;
if (!base.Enabled)
{
ControlPaint.DrawStringDisabled((IDeviceContext) e.Graphics, this.Text, this._linkFont, base.BackColor, this.ClientRectangle, textFormat);
}
else if ((this._linkFont != this._hoverFont) && this.IsMouseHover)
{
TextRenderer.DrawText((IDeviceContext) e.Graphics, this.Text, this._hoverFont, this.ClientRectangle, base.ForeColor, textFormat);
}
else
{
TextRenderer.DrawText((IDeviceContext) e.Graphics, this.Text, this._linkFont, this.ClientRectangle, base.ForeColor, textFormat);
}
}
}
protected override bool DoInvalidateWhenHover
{
get
{
return (this._linkFont != this._hoverFont);
}
}
private bool IsMouseHover
{
get
{
return base.MouseHovered;
}
}
public System.Windows.Forms.LinkBehavior LinkBehavior
{
get
{
return this._linkBehavior;
}
set
{
if (this._linkBehavior != value)
{
this._linkBehavior = value;
this.InnerDisposeFonts();
if (this._linkBehavior == System.Windows.Forms.LinkBehavior.HoverUnderline)
{
this._linkFont = base.Font;
this._hoverFont = new Font(base.Font, FontStyle.Underline);
}
else if (this._linkBehavior == System.Windows.Forms.LinkBehavior.AlwaysUnderline)
{
this._linkFont = new Font(base.Font, FontStyle.Underline);
this._hoverFont = this._linkFont;
}
else
{
this._linkFont = base.Font;
this._hoverFont = base.Font;
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -