如何改变按钮的边框颜色?
How to change Button's border colors?
我是 Visual Basic 的新手,我想更改 Button
的边框颜色,但我在 IDE 中没有看到任何选项(Visual Studio 2017)。有办法吗?
执行此操作的方法不是很明显,因为默认 Button
不允许使用彩色边框。
首先,您必须将 Button
的 FlatStyle
属性 设置为 FlatStyle.Flat
。然后你必须设置 Button
的 FlatAppearance.BorderColor
属性 为你选择的颜色。
如果需要,您可以在 Visual Studio 表单设计器中完成这两件事,或者您可以在代码中完成,如下所示:
Button1.Flatstyle = FlatStyle.Flat
Button1.FlatAppearance.BorderColor = Color.Yellow
您可以通过几种不同的方式来做到这一点。一种选择(快速简便)是从class System.Windows.Forms.Button
class 然后覆盖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
属性 例如边框大小等...
Button1.BorderColor = Drawing.Color.Red
我是 Visual Basic 的新手,我想更改 Button
的边框颜色,但我在 IDE 中没有看到任何选项(Visual Studio 2017)。有办法吗?
执行此操作的方法不是很明显,因为默认 Button
不允许使用彩色边框。
首先,您必须将 Button
的 FlatStyle
属性 设置为 FlatStyle.Flat
。然后你必须设置 Button
的 FlatAppearance.BorderColor
属性 为你选择的颜色。
如果需要,您可以在 Visual Studio 表单设计器中完成这两件事,或者您可以在代码中完成,如下所示:
Button1.Flatstyle = FlatStyle.Flat
Button1.FlatAppearance.BorderColor = Color.Yellow
您可以通过几种不同的方式来做到这一点。一种选择(快速简便)是从class System.Windows.Forms.Button
class 然后覆盖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
属性 例如边框大小等...
Button1.BorderColor = Drawing.Color.Red