This is my code:
buttonName = "btn" + y.ToString() + x.ToString();
Control btn = this.Controls.Find(buttonName, true)[0] as Control;
btn.BackColor = System.Drawing.Color.Blue;
However, I see no border color changing properties, or the like.
I used this code because I have a lot of buttons on my form, and any of those buttons' properties can change, so rather than call them out individually, I just made up that code which could handle them.
Is there a code similar to the one above, that would allow me to change the border color of the button?
To change the Outlined Button color in Flutter, simply set the style property of Outlined Button from the OutlinedButton. styleFrom() static method and set the backgroundColor property to change background color and primary property to change the text color.
I am not sure what sort of application you are working on, however in winforms there is no border property for a button directly on it, even in the designer. You can use a flat style button. And your type will have to be button.
you can do it like:
buttonName = "btn" + y.ToString() + x.ToString();
Button btn = this.Controls.Find(buttonName, true)[0] as Button;
btn.BackColor = System.Drawing.Color.Blue;
btn.FlatStyle = FlatStyle.Flat
btn.FlatAppearance.BorderColor = Color.Red;
btn.FlatAppearance.BorderSize = 1;
Unfortunately, this will only work on button with a FlatStyle.
you can use the flatAppearance.BorderColor
btn.FlatAppearance.BorderColor = System.Drawing.Color.Blue;
I know that this question is asked for a long time ago ( at 2011 ), but I think my comment will useful for someone : without using FlatStyle, you can use ControlPaint.DrawBorder in Paint event of the button you want to change the border color
private void btnName_Paint(object sender, PaintEventArgs e)
{
Button btn = (Button)sender;
ControlPaint.DrawBorder(e.Graphics, btn.ClientRectangle,
Color.LightGreen, 1, ButtonBorderStyle.Solid,
Color.LightGreen, 1, ButtonBorderStyle.Solid,
Color.LightGreen, 1, ButtonBorderStyle.Solid,
Color.LightGreen, 1, ButtonBorderStyle.Solid
);
}
According to Microsoft (link)
Applies to
.NET Framework
4.7.2, 4.7.1, 4.7, 4.6.2, 4.6.1, 4.6, 4.5.2, 4.5.1, 4.5, 4.0, 3.5, 3.0, 2.0, 1.1
Depending on your framework there is a new property called BorderColor
http://msdn.microsoft.com/en-us/library/system.windows.forms.flatbuttonappearance.bordercolor.aspx,
Have you checked that?
Also here is an example of something similar
Change border color of Windows Forms Control on focus
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With