添加一个具有3D边框且没有文本的标签(Label)
控件, 然后将高度设置为2。
var separator = new Label();
separator.BorderStyle = BorderStyle.Fixed3D;
separator.Height = 2;
protected override void OnPaint(PaintEventArgs e) {
Color back = this.BackColor;
Color dark = Color.FromArgb(back.R >> 1, back.G >> 1, back.B >> 1);
int y = button1.Bottom + 20;
using (var pen = new Pen(dark)) {
e.Graphics.DrawLine(pen, 30, y, this.ClientSize.Width - 30, y);
}
e.Graphics.DrawLine(Pens.White, 30, y+1, this.ClientSize.Width - 30, y+1);
}
button1
,以确保在表单重新缩放时,线条绘制在正确的高度。选择您自己的控件作为线条的参考。public class Separator : GroupBox
{
// Methods
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
{
base.SetBoundsCore(x, y, width, 3, specified);
}
// Properties
[DefaultValue("")]
public override string Text
{
get
{
return string.Empty;
}
set
{
}
}
}
一种方法是创建一个没有标签且高度为0(或者是1,我记不太清了)的分组框 - 我知道我以前用过这个技巧,即使感觉有点hacky :-)
您可以通过添加标签并将其文本设置为下划线 "_" 来获得分隔符效果。
我为此编写了一个自定义控件。您可以从NuGet
安装控件套件:
Install-Package ALMSTWKND -Version 1.0.0
安装完成后,它将被添加到工具箱窗格中。
stack.imgur.com
之外的其他主机可能会被许多组织屏蔽。 - John Alexiou