Click here to Skip to main content
16,019,152 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Presintaion_Layer.FM_TBL_Invoice inv = new FM_TBL_Invoice();

this.textBox2.Text = inv.comboStore.SelectedText;
Posted

Hi,
Lets assume there are two form1 and form2 and you have to pass the value of textbox on form1 to form2.
You can do this by two ways:
1.Using constructor.

C#
Class Form1
{
Form2 frm2Obj = new Form2(textbox.Text);
}


2. Using Property

C#
Class Form2
{
TextBoxValue {get; set;}
}


C#
Class Form1
{
Form2 frmObj2 = new Form2();
Form2.TextBoxValue = textbox.Text;
}
 
Share this answer
 
v2
As the question turned out to be very popular, and my previous answers often were not well understood, probably were not clear enough, I decided to write a Tips/Trick article complete with detailed code samples and explanations: Many Questions Answered at Once — Collaboration between Windows Forms or WPF Windows.

—SA
 
Share this answer
 
This is the popular question about form collaboration. The most robust solution is implementation of an appropriate interface in form class and passing the interface reference instead of reference to a "whole instance" of a Form. Please see my past solution for more detail: How to copy all the items between listboxes in two forms[^].

Please also see other solutions in this discussion. If the application is simple enough, the solution could be as simple as declaring of some internal property in one form and passing a reference to the instance of one form to the instance of another form. For more complex projects, such violation of strictly encapsulated style and loose coupling could add up the the accidental complexity of the code and invite mistakes, so the well-encapsulated solution would be preferable.

Please see also:
http://en.wikipedia.org/wiki/Accidental_complexity[^],
http://en.wikipedia.org/wiki/Loose_coupling[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900