📄 bdisplaynameandonlinestatus.cs
字号:
namespace Imps.Client.Pc.BizControls
{
using Imps.Client.Core;
using System;
using System.Drawing;
public class BDisplayNameAndOnlineStatus : BDropdownControl
{
private Font displayNameFont = new Font("宋体", 9f, FontStyle.Bold);
private Color displayNameForeColor = Color.Black;
private int displayNamePadding = 1;
private Size displayNameSize;
private int displayNameWidth;
private rich_string m_display_name = new rich_string(StringTable.PersonalInfo.NicknameGuest);
private string onlineStatusText = "(在线)";
private Font onlineStatusTextFont = new Font("宋体", 9f, FontStyle.Regular);
private Color onlineStatusTextForeColor = Color.Black;
private int onlineStatusTextPadding = 1;
private Size onlineStatusTextSize;
private int onlineStatusTextWidth;
private Rectangle rectDisplayName;
private Rectangle rectOnlineStatusText;
protected override void AdjustTextSize(Graphics g)
{
if (base.totalWidth > this.preferredSize.Width)
{
base.totalWidth = this.preferredSize.Width;
if (this.onlineStatusTextWidth > (base.totalWidth / 2))
{
if (this.displayNameSize.Width < (base.totalWidth / 2))
{
this.onlineStatusTextWidth = (((base.totalWidth - this.displayNameSize.Width) - base.dropDownButtonWidth) - 4) - this.displayNamePadding;
}
else
{
this.onlineStatusTextWidth = base.totalWidth / 2;
}
this.onlineStatusTextSize.Width = this.onlineStatusTextWidth;
}
this.displayNameSize.Width = (((base.totalWidth - this.onlineStatusTextWidth) - base.dropDownButtonWidth) - 4) - this.displayNamePadding;
}
if (this.displayNameSize.Width < 0)
{
this.displayNameSize.Width = 0;
this.onlineStatusTextSize.Width = (this.preferredSize.Width - base.dropDownButtonWidth) - 4;
if (this.onlineStatusTextSize.Width < 0)
{
this.onlineStatusTextSize.Width = 0;
}
}
this.rectDisplayName = new Rectangle(this.displayNamePadding, (base.Height - this.displayNameSize.Height) / 2, this.displayNameSize.Width, this.displayNameSize.Height);
this.rectOnlineStatusText = new Rectangle(this.rectDisplayName.Right + this.onlineStatusTextPadding, (base.Height - this.onlineStatusTextSize.Height) / 2, this.onlineStatusTextSize.Width + this.onlineStatusTextPadding, this.onlineStatusTextSize.Height);
}
protected override int MeasureTextWidth(Graphics g)
{
SizeF ef = this.m_display_name.MeasureText(g, this.displayNameFont);
this.displayNameSize = new Size(((int) ef.Width) + 2, base.Height);
SizeF ef2 = g.MeasureString(this.onlineStatusText, this.OnlineStatusTextFont);
this.onlineStatusTextSize = new Size(((int) ef2.Width) + 2, base.Height);
this.displayNameWidth = this.displayNameSize.Width + this.displayNamePadding;
this.onlineStatusTextWidth = this.onlineStatusTextSize.Width + (2 * this.onlineStatusTextPadding);
return (this.displayNameWidth + this.onlineStatusTextWidth);
}
protected override void PaintText(Graphics g)
{
using (StringFormat format = new StringFormat())
{
format.Alignment = StringAlignment.Near;
format.LineAlignment = StringAlignment.Center;
format.FormatFlags |= StringFormatFlags.NoWrap;
format.Trimming = StringTrimming.EllipsisCharacter;
using (Brush brush = new SolidBrush(this.OnlineStatusTextForeColor))
{
g.DrawString(this.onlineStatusText, this.OnlineStatusTextFont, brush, this.rectOnlineStatusText, format);
}
Color foreColor = base.Enabled ? this.displayNameForeColor : Color.FromArgb(0x55, 0x55, 0x55);
this.m_display_name.Draw(g, this.displayNameFont, foreColor, this.rectDisplayName, format);
}
}
public string DisplayName
{
get
{
return this.m_display_name.plane_text;
}
set
{
this.m_display_name.plane_text = (value == null) ? string.Empty : value;
this.Refresh();
}
}
public Font DisplayNameFont
{
get
{
return this.displayNameFont;
}
set
{
this.displayNameFont = value;
}
}
public Color DisplayNameForeColor
{
get
{
return this.displayNameForeColor;
}
set
{
this.displayNameForeColor = value;
}
}
public string OnlineStatusText
{
get
{
return this.onlineStatusText;
}
set
{
if (!string.IsNullOrEmpty(value) && !string.Equals(this.onlineStatusText, value))
{
this.onlineStatusText = value;
this.Refresh();
}
}
}
public Font OnlineStatusTextFont
{
get
{
return this.onlineStatusTextFont;
}
set
{
this.onlineStatusTextFont = value;
}
}
public Color OnlineStatusTextForeColor
{
get
{
return this.onlineStatusTextForeColor;
}
set
{
this.onlineStatusTextForeColor = value;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -