Connecting Tech Pros Worldwide Forums | Help | Site Map

sharing data between forms / passing data from one to another

Newbie
 
Join Date: Nov 2009
Posts: 1
#1: 3 Weeks Ago
hello,

i'm a begginer in c# and even though i searched google and used two books for begginers i'm just not able to solve this problem. please help me on this:

so i have two forms form1 and form2

lets say that in form1 is textboxA and button that opens form2, so when i click on the button i open form2 and i want from textboxB in form2 pass data to form1 textboxA (for example when i click on ok button in form2 and close it). How can i do that?

how can i access form1 textboxA from form2? is it even possible? should i do it some other way?

thank you for any help

ps: for example is to possible to do some textbox "public" so i can access that from any form?

Member
 
Join Date: Aug 2009
Posts: 33
#2: 3 Weeks Ago

re: sharing data between forms / passing data from one to another


Check out the following code.
Expand|Select|Wrap|Line Numbers
  1.  // This method demonstrates a pattern for making thread-safe
  2.         // calls on a Windows Forms control. 
  3.         //
  4.         // If the calling thread is different from the thread that
  5.         // created the TextBox control, this method creates a
  6.         // SetTextCallback and calls itself asynchronously using the
  7.         // Invoke method.
  8.         //
  9.         // If the calling thread is the same as the thread that created
  10.         // the TextBox control, the Text property is set directly. 
  11.  
  12.         private void SetText(string text)
  13.         {
  14.             // InvokeRequired required compares the thread ID of the
  15.             // calling thread to the thread ID of the creating thread.
  16.             // If these threads are different, it returns true.
  17.             if (this.textBox1.InvokeRequired)
  18.             {    
  19.                 SetTextCallback d = new SetTextCallback(SetText);
  20.                 this.Invoke(d, new object[] { text });
  21.             }
  22.             else
  23.             {
  24.                 this.textBox1.Text = text;
  25.             }
  26.         }
For link to to
http://msdn.microsoft.com/en-us/libr...28(VS.80).aspx
Reply