c# - pictureBox, graphics and messageBox -


i have problem these elements. try draw line graphics , put on picturebox. call messagebox , runs in of mainwindow. of cause can't use mainwindow because program wait clicking buttons of mesagebox. don't see it. button alt helps me only, or alt+tab, stupid. so, code:

public partial class form1 : form { graphics g; bitmap btm;

    public form1()     {         initializecomponent();     }      private void form1_load(object sender, eventargs e)     {         btm = new bitmap(picturebox1.size.width, picturebox1.size.height);         g = creategraphics();         g = graphics.fromimage(btm);         pen p = new pen(brushes.red);         g.drawline(p, 0, 0, btm.size.width, btm.size.height);                     picturebox1.refresh();         g.dispose();     }      protected override void onclosing(canceleventargs e)     {         dialogresult dr = messagebox.show("exit?", "exit", messageboxbuttons.yesno);         if (dr == dialogresult.no) e.cancel = true; else e.cancel = false;     }      private void picturebox1_paint(object sender, painteventargs e)     {         picturebox1.image = btm;     } } 

tell me, problem? thanks

when form refreshed, paint event called. avoid custom drawing @ point setting flag.

bool updatepicturebox = true;  private void picturebox1_paint(object sender, painteventargs e) {     if(updatepicturebox)         picturebox1.image = btm; }  protected override void onclosing(canceleventargs e) {     updatepicturebox = false;     dialogresult dr = messagebox.show(this,"exit?", "exit", messageboxbuttons.yesno);     if (dr == dialogresult.no) e.cancel = true; else e.cancel = false; } 

however, can avoid entire issue drawing within paint event itself. suggest doing instead of using flag method above.

private void picturebox1_paint(object sender, painteventargs e) {     var g = e.graphics;                 using (pen p = new pen(brushes.red))     {         g.drawline(p, 0, 0, picturebox1.width, picturebox1.height);     } } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -