Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to change the Border Color of a label

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.

like image 413
Stewbob Avatar asked Jun 12 '09 16:06

Stewbob


People also ask

How do I change the border on a widget?

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.

How do I change the border color in Groupbox?

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.


2 Answers

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

like image 103
orandov Avatar answered Oct 02 '22 08:10

orandov


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!

like image 45
Stewbob Avatar answered Oct 02 '22 10:10

Stewbob