【发布时间】:2018-01-25 12:02:50
【问题描述】:
当用户悬停标签时,它会在标签上添加top-border 和bottom-border。
类似这样的东西:http://ianlunn.github.io/Hover/ -> 边框过渡 -> 中心下划线。
但是,我只知道如何定义普通边框。我什至不能改变边框的颜色,他的宽度等等......
这是我目前所取得的成就:
designer.cs:
this.label1.BackColor = System.Drawing.SystemColors.ActiveCaption;
this.label1.Font = new System.Drawing.Font("Arial", 16F, System.Drawing.FontStyle.Bold);
this.label1.Location = new System.Drawing.Point(124, 187);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(217, 65);
this.label1.TabIndex = 0;
this.label1.Text = "Something Cool";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.label1.MouseHover += new System.EventHandler(this.label1_MouseHover);
this.label1.MouseLeave += new System.EventHandler(this.label1_MouseLeave);
cs:
private void label1_MouseHover(object sender, EventArgs e)
{
label1.BorderStyle = BorderStyle.FixedSingle;
label1.Font = new Font("Arial", 18, FontStyle.Bold);
}
private void label1_MouseLeave(object sender, EventArgs e)
{
// initialize
label1.BorderStyle = BorderStyle.None;
label1.Font = new Font("Arial", 16, FontStyle.Bold);
}
【问题讨论】:
-
这比你想象的要大得多。您必须将控件继承到您自己的控件中。接管
Paint处理程序,并自己绘制它。您必须响应所有用户输入并做出相应的反应,绘制您希望看到的一切。这将不是一个容易的项目。如果您仍有选择的余地,您会发现 WPF 使这类事情变得容易得多。 -
虽然在
WinForms中做到这一点并不难。你根本不需要接触继承。 -
@L.Guthardt 嗨,谢谢。我做到了:
ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, Color.Red, ButtonBorderStyle.Solid);它确实触及了所有标签,但我希望它只在顶部和底部,我该如何实现?