格式介绍:
Webdings是一个TrueType的dingbat字体,于1997年发表,搭载在其后的Microsoft Windows视窗系统内,大多的字形都没有Unicode的相对字。
这里我们用0(最小化),1(放大),2(缩放),r(关闭)模拟对应窗口按键。

废话不多说直接上代码:
public partial class UiconButton : Button
{
public UiconButton()
{
InitializeComponent();
//尺寸 字体 字号
this.Size = new Size(30, 30);
this.Font = new Font("Webdings", 10.8f);
this.FlatStyle = FlatStyle.Flat;
this.FlatAppearance.BorderSize = 0;
this.Text = "0";
this.ForeColor = Color.Silver;
this.BackColor = Color.Transparent;
}
protected override void OnMouseEnter(EventArgs e)
{
base.OnMouseEnter(e);
this.BackColor = Color.FromArgb(53, 61, 134);
}
protected override void OnMouseLeave(EventArgs e)
{
base.OnMouseLeave(e);
this.BackColor = Color.Transparent;
}
/// <summary>
/// 不显示聚焦框
/// </summary>
protected override bool ShowFocusCues
{
get { return false; }
}
}
注意:创建用户控件后需要把继承类改成 Button 然后删除这行才能使用

使用方法:
修改对应文本即可

主窗口使用代码:
/// <summary>
/// 窗口缩小化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButMin_Click(object sender, EventArgs e)
{
if (this.WindowState != FormWindowState.Minimized) {
this.WindowState = FormWindowState.Minimized;
}
}
/// <summary>
/// 窗口最大化
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButMax_Click(object sender, EventArgs e)
{
if (this.WindowState == FormWindowState.Maximized)
{
this.WindowState = FormWindowState.Normal;
this.ButMax.Text = "1";
}
else {
this.WindowState = FormWindowState.Maximized;
this.ButMax.Text = "2";
}
}
/// <summary>
/// 关闭窗口
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ButClose_Click(object sender, EventArgs e)
{
Application.Exit();
}
/// <summary>
/// 窗口关闭事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
{
if (MessageBox.Show("是否退出界面?", "提示",
MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2) == DialogResult.OK)
{
Application.ExitThread();
}
else e.Cancel = true;
}
效果图


505

被折叠的 条评论
为什么被折叠?



