-1

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 here.

Community
  • 1
  • 1
Ankky
  • 47
  • 2
  • 12
  • You've already accepted an answer. If you have a new question, post a new question. Document it properly with your code. – LarsTech Nov 21 '16 at 17:02

1 Answers1

2

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);
    
Pikoh
  • 7,582
  • 28
  • 53
  • Thanks... This helped I never used it so didn't knew about it. – Ankky Nov 21 '16 at 14:35
  • Hi when I implement the same for panel it shows error. Error: No overload for 'panel1_Paint' matches delegate 'PaintEventHandler' – Ankky Nov 21 '16 at 16:56
  • i guess your `panel1_paint` method has the wrong signature. It should be something like this: `private void panel1_Paint(object sender, PaintEventArgs e)` – Pikoh Nov 21 '16 at 17:10