c# - Can't draw on Picturebox -


suppose have form picturebox on it:

where problem? rectangle disapears on picture box. why?

   private void picturebox1_paint(object sender, painteventargs e)     {         graphics gr = picturebox1.creategraphics();         gr.fillrectangle(brushes.red, new rectangle(10, 10, 50, 50));      } 

i checked , yeah case mentioned in comments.

the problem not taking reference of graphics when painting instead pushing rectangle in picturebox's graphics wont rendered.

to right need use e.graphics refrence on graphic going painted.

so correct code is:

private void picturebox1_paint(object sender, painteventargs e) {     graphics gr = e.graphics;     gr.fillrectangle(brushes.red, new rectangle(10, 10, 50, 50));  } 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -