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):

enter image description here

input in form 2 (put value in text box) :

enter image description here

get text in form 1 on form 2 close event.

enter image description here

you can modify according needs.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -