forked from unknwon/CharmControlLibrary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CharmLinkLabel.cs
94 lines (89 loc) · 3.11 KB
/
CharmLinkLabel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#region 文档说明
/* ****************************************************************************************************
* 文档作者:无闻
* 创建日期:2013年2月8日
* 文档用途:CharmLinkLabel - 链接标签控件
* -----------------------------------------------------------------------------------------------------
* 修改记录:
* 2013-03-03:针对CSBox界面标准2.0进行升级改造
* -----------------------------------------------------------------------------------------------------
* 参考文献:
*
* *****************************************************************************************************/
#endregion
#region 命名空间引用
using System.Drawing;
#endregion
namespace CharmControlLibrary
{
/// <summary>
/// 表示 CharmControlLibrary.CharmLinkLabel 链接标签控件
/// </summary>
public class CharmLinkLabel : CharmControl
{
#region 属性
/// <summary>
/// 获取或设置控件的状态
/// </summary>
public override ControlStatus ControlStatus
{
get { return base.ControlStatus; }
set
{
// 获取控件状态
base.ControlStatus = value;
// 判断字体是否加粗
bool isBold = Font.Bold;
// 根据控件状态判断是否需要设置下划线
if (base.ControlStatus == ControlStatus.Normal)
{
// 常态,不需要设置
if (isBold) // 判断字体是否加粗
Font = new Font(Font.Name, Font.Size, FontStyle.Bold);
else
Font = new Font(Font.Name, Font.Size);
}
else
{
// 非常态,需要设置
if (isBold) // 判断字体是否加粗
Font = new Font(Font.Name, Font.Size, FontStyle.Underline | FontStyle.Bold);
else
Font = new Font(Font.Name, Font.Size, FontStyle.Underline);
}
}
}
/// <summary>
/// 获取或设置与此控件关联的文本
/// </summary>
public override string Text
{
get { return base.Text; }
set
{
base.Text = value;
// 重新计算工作区矩形
SizeF sf;
using (Graphics g = Graphics.FromImage(new Bitmap(100, 100)))
{
sf = g.MeasureString(base.Text, Font);
}
// 设置新的工作区矩形参数
base.Width = (int)sf.Width;
base.Height = (int)sf.Height;
}
}
#endregion
#region 构造方法
/// <summary>
/// 初始化 CharmLinkLabel 类的新实例
/// </summary>
public CharmLinkLabel()
: base()
{
// * 初始化属性 *
ControlType = ControlType.CharmLinkLabel;
}
#endregion
}
}