且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Windows 窗体分隔符控件

更新时间:2023-12-06 09:05:22

即使已经回答了这个问题,我还是根据 smoore 的回答发现以下是我所需要的.>

创建一个新控件.编辑代码如下:

public 部分类 Line : Label{公共覆盖布尔自动调整大小{得到{返回假;}}公共覆盖大小 MaximumSize{得到{返回新大小(int.MaxValue,2);}}公共覆盖尺寸最小尺寸{得到{返回新大小(1, 2);}}公共覆盖字符串文本{得到{返回 "";}}公共线路(){初始化组件();this.AutoSize = false;this.Height = 2;this.BorderStyle = BorderStyle.Fixed3D;}}

Line 替换为您想要的控件类名.这将放置一个分隔符,允许您在设计器中调整大小并禁用添加文本,更改自动大小会强制大小的高度为 2,宽度为您想要的任何值,并禁用添加文本.

Where in VS2010 can I find a horizontal separator control, as can be found in Outlook settings (screenshots below)?

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.

Even though this has been answered, I found the following to be what I need based partly on smoore's answer.

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. 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.