winforms - Sending data from Form2 to Form1 once the user inputs the required things in some text boxes in C# -
i making program friend , need when types in number corresponding form opens when hits 'go' form open. have part done. issue have when new form opens have series of text boxes needs input data '1 can of fresh beans' , other stuff in other text boxes on form. when done typing in required things hit submit button format code accordingly way have set this
richtextbox1.text += "this text type before" + amntitemstxtbox + " , other stuff";
so kind of want happen. know may have confused people ran issue how take typed in form 2 , send richtextbox in form 1 when hits button can copy , paste else later on. know code seems bit "new" starting out c# , wanting learn more. appreciated.
i have done in sample project. may you.
form 1:
private void button1_click(object sender, eventargs e) { form2 frm2 = new form2(); frm2.txtmessagechanged += new eventhandler(txt_messagechanged); frm2.showdialog(this); } private void txt_messagechanged(object sender, eventargs e) { txtmessage.text = (string)sender; }
form 2 :
public eventhandler txtmessagechanged { get; set; } private void form2_formclosing(object sender, formclosingeventargs e) { if (textbox1.text != string.empty) { string = textbox1.text; if (txtmessagechanged != null) txtmessagechanged(a, null); } else { messagebox.show("fill data in textbox"); e.cancel = true; }
image of form 1 (on button click event open form 2):
input in form 2 (put value in text box) :
get text in form 1 on form 2 close event.
you can modify according needs.
Comments
Post a Comment