简体   繁体   English

Windows窗体分隔符控件

[英]Windows Forms Separator Control

Where in VS2010 can I find a horizontal separator control, as can be found in Outlook settings (screenshots below)? 在VS2010中哪里可以找到水平分隔符控件,可以在Outlook设置中找到(下面的屏幕截图)?

https://jira.atlassian.com/secure/attachment/14933/outlook+settings.jpg http://www.keithfimreite.com/Images/OutlookSettings3.gif https://jira.atlassian.com/secure/attachment/14933/outlook+settings.jpg http://www.keithfimreite.com/Images/OutlookSettings3.gif

Note: VB.NET preferred, but C# answers okay. 注意:VB.NET首选,但C#的答案还可以。

If I'm not mistaken, that's just a Line control, but I don't think that control exists anymore. 如果我没弄错,那只是一个Line控件,但我不认为控件存在了。 Here is a workaround. 是一个解决方法。

label1.AutoSize = False
label1.Height = 2
label1.BorderStyle = BorderStyle.Fixed3D

Even though this has been answered, I found the following to be what I need based partly on smoore 's answer. 虽然已经回答了这个问题,但我发现以下内容是我需要的部分基于smoore的回答。

Create a new control. 创建一个新控件。 Edit the code to be the following: 编辑代码如下:

public partial class Line : Label
{
    public override bool AutoSize
    {
        get
        {
            return false;
        }
    }

    public override Size MaximumSize
    {
        get
        {
            return new Size(int.MaxValue, 2);
        }
    }

    public override Size MinimumSize
    {
        get
        {
            return new Size(1, 2);
        }
    }

    public override string Text
    {
        get
        {
            return "";
        }
    }

    public Line()
    {
        InitializeComponent();
        this.AutoSize = false;
        this.Height = 2;
        this.BorderStyle = BorderStyle.Fixed3D;
    }
}

Replace Line with the control's class name you want. Line替换为所需的控件类名。 This will put a separator that will allow you to resize in the designer and disables adding text, changing the autosize forces the size's height to be 2 and width to be whatever you want, and disables adding text. 这将放置一个分隔符,允许您在设计器中调整大小并禁用添加文本,更改自动调整大小强制大小的高度为2,宽度为您想要的任何值,并禁用添加文本。

It's not actually included in the standard set of controls (pretty sure it used to be back in the day!) but you can easily create your own or cheat by using a GroupBox with no text and a height of 1px. 它实际上并没有被包含在标准的控件集中(非常确定它曾经在当天回来了!)但是你可以通过使用没有文本和高度为1px的GroupBox轻松创建自己的或作弊。

UserControl to provide the same thing: (Not written by me, source: http://social.msdn.microsoft.com/Forums/en-US/winforms/thread/0d4b986e-3ed0-4933-a15d-4b42e02005a7/ ) UserControl提供相同的东西:(不是我写的,来源: http//social.msdn.microsoft.com/Forums/en-US/winforms/thread/0d4b986e-3ed0-4933-a15d-4b42e02005a7/

public partial class LineSeparator:UserControl
{

    public LineSeparator()
    {
        InitializeComponent();
        this.Paint += new PaintEventHandler(LineSeparator_Paint);
        this.MaximumSize = new Size(2000, 2);
        this.MinimumSize = new Size(0, 2);
        this.Width = 350;
    }

    private void LineSeparator_Paint(object sender, PaintEventArgs e)
    {
        Graphics g = e.Graphics;
        g.DrawLine(Pens.DarkGray, new Point(0, 0), new Point(this.Width, 0));
        g.DrawLine(Pens.White, new Point(0, 1), new Point(this.Width, 1));
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM