How can I access a Button Press from a different Form? C# -
so creating text editor, , want have popup when user attempts close application asking whether sure want this, in windows' notepad. not using messageboxes, instead using custom form. how can info button press in form2 , access in form1?
thanks in advance responses. if there's other info can provide useful, please let me know!
edit mean: have created form 3 buttons: save, don't save, , cancel. want info they've pressed. return of button , go there?
you need have property pull info out of on secondary form. you'll still want use showdialog() , can check dialog result. memory code may not build, should give idea.
on form2
public string text { { return this.sometextboxontheform.text; } set { this.sometextboxontheform.text = value; } } //called "save" button. public void save() { this.dialogresult = dialogresult.ok; this.close(); } //called either "dontsave" button or "cancel" button. public void cancel() { this.dialogresult = dialogresult.cancel; this.close(); }
on other form1
public void showform2() { var form = new form2(); //you set default text here form.text = "enter message..."; var result = form.showdialog(); if( result == dialogresult.ok ) { var finaltext = form.text; //do text } }
Comments
Post a Comment