I'm working in VB, VS2008, winforms. I've got some labels to create, and I'm using the BorderStyle = FixedSingle.
Is there any way to change the color of this border? It is always defaulting to black.
There is no way to change the border color of a widget, the border color is tied to the background color of the widget. Instead, you can turn off the border, and then use a frame widget where you can set the background color of the frame.
Umh I think that the only way to do that, is to create your own Personalized Control that inherits from Group Box, and Overrides the OnPaint Method, then you are able to create a color property and use it in the paint method.
If you don't want to create a custom control you can try this:
Hook up to the Label's paint event.
void label1_Paint(object sender, PaintEventArgs e) { ControlPaint.DrawBorder(e.Graphics, label1.DisplayRectangle, Color.Blue, ButtonBorderStyle.Solid); }
Taken from here by Andrej Tozon
I combined the solutions from robin.ellis and orandov to get a result that worked the best for me. I created a custom control that inherited the Label object and then overrode the OnPaint event.
Public Class nomLabel Inherits Label Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs) MyBase.OnPaint(e) ControlPaint.DrawBorder(e.Graphics, e.ClipRectangle, myColor, ButtonBorderStyle.Solid) End Sub End Class
Thanks for the help!
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