How to change Button's border colors?
Solution 1
The way to do this is not very obvious as the default Button
doesn't allow for a coloured border.
First you have to set the Button
's FlatStyle
property to FlatStyle.Flat
. Then you have to set the Button
's FlatAppearance.BorderColor
property to the colour of your choice.
You can do both of those things in the Visual Studio form designer if you want, or you can do it in code like this:
Button1.Flatstyle = FlatStyle.Flat
Button1.FlatAppearance.BorderColor = Color.Yellow
Solution 2
You can do this is a few different ways. One option (quick and easy) is to subclass the System.Windows.Forms.Button
class and then override the OnPaint
method...
For example:
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
Another option is to create your own button control, this takes time and you could benefit better as you would have more control in what you would like to do. If your button's FlatStyle
property is set to "Flat" you could change the FlatApperance
property in designer such as border-size and etc...
Solution 3
Button1.BorderColor = Drawing.Color.Red
jSystem75
Updated on June 04, 2022Comments
-
jSystem75 almost 2 years
I'm new to Visual Basic and I want to change the border color of a
Button
, but I don't see any option to do that in the IDE (Visual Studio 2017). Is there a way to do this?