📄 notifywindowlabel.cs
字号:
namespace Imps.Client.Pc.BizControls.NotifyWindows
{
using Imps.Client.Core;
using System;
using System.Drawing;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
public class NotifyWindowLabel : INotifyWindowElement, IDisposable
{
private bool clickable;
private bool enableSelectionRectangle;
private StringFormat format;
private Color hoverTextColor;
private Font hoverTextFont;
private bool isMouseOver;
private rich_string m_display_text = new rich_string("");
private System.Drawing.Rectangle realTextRectangle;
private string text = "";
private Color textColor;
private Font textFont;
private System.Drawing.Rectangle textRectangle;
public event NotifyWindowEventHandler Click;
public event NotifyWindowEventHandler MouseDown;
public event NotifyWindowEventHandler MouseOut;
public event NotifyWindowEventHandler MouseOver;
public event NotifyWindowEventHandler MouseUp;
public NotifyWindowLabel(string text, System.Drawing.Rectangle textRectangle)
{
this.Text = text;
this.Rectangle = textRectangle;
this.format = new StringFormat();
this.format.LineAlignment = StringAlignment.Center;
this.format.FormatFlags = StringFormatFlags.LineLimit | StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.FitBlackBox;
this.format.Trimming = StringTrimming.EllipsisCharacter;
this.textColor = Color.Black;
this.hoverTextColor = Color.Black;
this.textFont = new Font("宋体", 12f, FontStyle.Regular, GraphicsUnit.Pixel);
this.hoverTextFont = new Font("宋体", 12f, FontStyle.Regular, GraphicsUnit.Pixel);
this.clickable = false;
this.enableSelectionRectangle = false;
this.isMouseOver = false;
}
protected void CalculateRectangles(Graphics g)
{
SizeF ef = g.MeasureString(this.Text, this.HoverTextFont, this.Rectangle.Width, this.Format);
if (ef.Height > this.Rectangle.Height)
{
this.RealRectangle = new System.Drawing.Rectangle(((this.Rectangle.Width - ((int) ef.Width)) / 2) + this.Rectangle.Left, this.Rectangle.Top, (int) ef.Width, this.Rectangle.Height);
}
else
{
this.RealRectangle = new System.Drawing.Rectangle(((this.Rectangle.Width - ((int) ef.Width)) / 2) + this.Rectangle.Left, ((this.Rectangle.Height - ((int) ef.Height)) / 2) + this.Rectangle.Top, (int) ef.Width, (int) ef.Height);
}
this.RealRectangle.Inflate(8, 8);
}
public void Dispose()
{
}
public virtual void Draw(Graphics g)
{
this.CalculateRectangles(g);
if (this.Text.Length != 0)
{
if (this.IsMouseOver)
{
using (Brush brush = new SolidBrush(this.hoverTextColor))
{
g.DrawString(this.Text, this.HoverTextFont, brush, this.Rectangle, this.Format);
}
if (this.EnableSelectionRectangle)
{
ControlPaint.DrawBorder3D(g, this.RealRectangle, Border3DStyle.Etched, Border3DSide.Bottom | Border3DSide.Right | Border3DSide.Top | Border3DSide.Left);
}
}
else
{
using (Brush brush2 = new SolidBrush(this.TextColor))
{
g.DrawString(this.Text, this.TextFont, brush2, this.Rectangle, this.Format);
}
}
}
}
public void OnClick(NotifyWindowEventArgs e)
{
if (this.Click != null)
{
this.Click(this, e);
}
}
public void OnMouseDown(NotifyWindowEventArgs e)
{
this.IsMouseOver = true;
if (this.MouseDown != null)
{
this.MouseDown(this, e);
}
}
public void OnMouseOut(NotifyWindowEventArgs e)
{
this.IsMouseOver = false;
if (this.MouseOut != null)
{
this.MouseOut(this, e);
}
}
public void OnMouseOver(NotifyWindowEventArgs e)
{
this.IsMouseOver = true;
if (this.MouseOver != null)
{
this.MouseOver(this, e);
}
}
public void OnMouseUp(NotifyWindowEventArgs e)
{
this.IsMouseOver = false;
if (this.MouseUp != null)
{
this.MouseUp(this, e);
}
}
public bool Clickable
{
get
{
return this.clickable;
}
set
{
this.clickable = value;
}
}
public bool EnableSelectionRectangle
{
get
{
return this.enableSelectionRectangle;
}
set
{
this.enableSelectionRectangle = value;
}
}
public StringFormat Format
{
get
{
return this.format;
}
set
{
this.format = value;
}
}
public Color HoverTextColor
{
get
{
return this.hoverTextColor;
}
set
{
this.hoverTextColor = value;
}
}
public Font HoverTextFont
{
get
{
return this.hoverTextFont;
}
set
{
this.hoverTextFont = value;
}
}
public bool IsMouseOver
{
get
{
return this.isMouseOver;
}
set
{
this.isMouseOver = value;
}
}
public System.Drawing.Rectangle RealRectangle
{
get
{
return this.realTextRectangle;
}
set
{
this.realTextRectangle = value;
}
}
public System.Drawing.Rectangle Rectangle
{
get
{
return this.textRectangle;
}
set
{
this.textRectangle = value;
}
}
public string Text
{
get
{
return this.text;
}
set
{
this.text = value;
}
}
public Color TextColor
{
get
{
return this.textColor;
}
set
{
this.textColor = value;
}
}
public Font TextFont
{
get
{
return this.textFont;
}
set
{
this.textFont = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -