Ankky Ankky - 1 year ago 282
C# Question

Windows forms c# change label and panel border color not working

I wrote the following code for changing the border color of a label but it is not working. It is same as how I gave in the label properties.

void label1_Paint(object sender, PaintEventArgs e)
ControlPaint.DrawBorder(e.Graphics, label1.DisplayRectangle, Color.Red, ButtonBorderStyle.Solid);

I found this code from here.

Answer Source

I tried your code and it works fine. So i guess the problem is you haven't subscribed to your label Paint event. So you must do one of this two options:

  • Select your label properties,go to the events and double click the Paint event.

  • Add this to your Form's constructor or Load event:

    label1.Paint += new System.Windows.Forms.PaintEventHandler(this.label1_Paint);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download