【问题标题】:How to change Button's border colors?如何更改 Button 的边框颜色?
【发布时间】:2017-12-02 13:44:45
【问题描述】:

我是 Visual Basic 新手,我想更改 Button 的边框颜色,但我在 IDE (Visual Studio 2017) 中没有看到任何选项。有没有办法做到这一点?

【问题讨论】:

    标签: vb.net button colors border


    【解决方案1】:

    这样做的方法不是很明显,因为默认的Button 不允许有彩色边框。

    首先您必须将ButtonFlatStyle 属性设置为FlatStyle.Flat。然后您必须将ButtonFlatAppearance.BorderColor 属性设置为您选择的颜色。

    如果您愿意,您可以在 Visual Studio 表单设计器中完成这两件事,或者您可以在如下代码中完成:

    Button1.Flatstyle = FlatStyle.Flat
    Button1.FlatAppearance.BorderColor = Color.Yellow
    

    【讨论】:

      【解决方案2】:

      您可以通过几种不同的方式做到这一点。一种选择(快速简单)是继承 System.Windows.Forms.Button 类,然后覆盖 OnPaint 方法...

      例如:

       Protected Overrides Sub OnPaint(ByVal pevent As System.Windows.Forms.PaintEventArgs)
              MyBase.OnPaint(pevent)
              Dim rect As New Rectangle(0, 0, Me.Width, Me.Height)
              Dim mPen As New Pen(Color.Red, 3)
              pevent.Graphics.DrawRectangle(mPen, rect)
          End Sub
      

      另一种选择是创建您自己的按钮控件,这需要时间并且您可以更好地受益,因为您可以更好地控制您想做的事情。如果您的按钮的 FlatStyle 属性设置为“Flat”,您可以在设计器中更改 FlatApperance 属性,例如边框大小等...

      【讨论】:

        【解决方案3】:
        Button1.BorderColor = Drawing.Color.Red
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-01-05
          • 1970-01-01
          • 2010-09-09
          • 2020-01-12
          • 2013-02-18
          • 1970-01-01
          • 2021-09-27
          • 2019-11-23
          相关资源
          最近更新 更多