samedi 3 mars 2018

C# Windows Forms Paint Event| "if" <- isn't really working

I got a problem with the paint event in windows forms. So everything works fine for me, but if I use a "If" it won't work. For example if I do:

private void Form1_Paint(object sender, PaintEventArgs e) {
   graphics = e.Graphics;
   graphics.DrawRectangle(pen, new Rectangle(100, 100, 200, 200));
}

everything works fine, but if I do:

private void Form1_Paint(object sender, PaintEventArgs e) {
   if(drawRect) {
     graphics = e.Graphics;
     graphics.DrawRectangle(pen, new Rectangle(100, 100, 200, 200));
   }
}

It won't draw anything except "drawRect" is from the beginning true, but it won't stop drawing if you later change it to false. I can't find the bug, error or whatever.

I hope you can help me. Already Thanks.

Aucun commentaire:

Enregistrer un commentaire