【问题标题】:Windows Forms Separator ControlWindows 窗体分隔符控件
【发布时间】:2011-08-26 16:48:27
【问题描述】:

在 VS2010 中哪里可以找到水平分隔符控件,可以在 Outlook 设置中找到(下面的屏幕截图)?

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

注意:首选 VB.NET,但 C# 答案还可以。

【问题讨论】:

    标签: c# vb.net winforms visual-studio-2010


    【解决方案1】:

    它实际上并没有包含在标准控件集中(很确定它曾经回到过去!)但您可以使用没有文本且高度为 1 像素的 GroupBox 轻松创建自己的或作弊。

    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));
        }
    }
    

    【讨论】:

    • 让你想知道为什么 2000 的限制,甚至不足以覆盖 2 屏幕设置。让我想起所罗门的劣质程序。
    【解决方案2】:

    如果我没记错的话,那只是一个 Line 控件,但我认为该控件不再存在。 Here 是一种解决方法。

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

    【讨论】:

      【解决方案3】:

      即使已经回答了这个问题,我还是根据 smoore 的回答发现了以下内容。

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

      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;
          }
      }
      

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-12-20
        • 1970-01-01
        • 2011-06-30
        • 1970-01-01
        • 2010-11-28
        • 2010-12-02
        相关资源
        最近更新 更多