c# - How can I change my Form's text after I show a messagebox? -


i making notepad program , having problem; on new button, have code:

private void new()     {         if (us == true)         {             dialogresult dr = messagebox.show("do want save changes to: " + filepath, "save changes", messageboxbuttons.yesnocancel, messageboxicon.information);             if (dr == dialogresult.yes)                 save();             else if (dr == dialogresult.no)             {                 filename = null;                 undotoolstripmenuitem.enabled = false;                 undotoolstripmenuitem1.enabled = false;                 redotoolstripmenuitem.enabled = false;                 redotoolstripmenuitem1.enabled = false;                 = false;                 form1.activeform.text = "untitled - padnotepro";                 richtextbox1.clear();             }             else if (dr == dialogresult.cancel)                 close();         }         else         {             filename = null;             undotoolstripmenuitem.enabled = false;             undotoolstripmenuitem1.enabled = false;             redotoolstripmenuitem.enabled = false;             redotoolstripmenuitem1.enabled = false;             form1.activeform.text = "untitled - padnotepro";             richtextbox1.clear();         }     } 

us means un-saved, see if saved, if = true, not saved.

when click no on dialogbox, runs code:

else if (dr == dialogresult.no)             {                 filename = null;                 undotoolstripmenuitem.enabled = false;                 undotoolstripmenuitem1.enabled = false;                 redotoolstripmenuitem.enabled = false;                 redotoolstripmenuitem1.enabled = false;                 = false;                 form1.activeform.text = "untitled - padnotepro";                 richtextbox1.clear();             } 

what having problem with, the: form1.activeform.text = "untitled - padnotepro";, seems skipping line of code. think has messagebox, can't figure out. know why?

edit: think might have form not being active @ time.

i have figured out problem myself. cannot run code form in code messagebox. have use backgroundworker. reference, here code used:

backgroundworker changeformtext = new backgroundworker(); public form1() {     initializecomponent();     changeformtext.dowork += changeformtext_dowork; } void changeformtext_dowork(object sender, doworkeventargs e) {     invoke(new action(doit)); } void doit() {     this.text = "untitled - padnotepro"; } private void new() {     if (us == true)     {         dialogresult dr = messagebox.show("do want save changes to: untitled?", "save changes", messageboxbuttons.yesnocancel, messageboxicon.information);         if (dr == dialogresult.yes)             save();         else if (dr == dialogresult.no)         {             changeformtext.runworkerasync();         }         else if (dr == dialogresult.cancel)             close();     }     else     {         changeformtext.runworkerasync();     } } 

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 -