| | |
Passing data between forms
Please support our C# advertiser: Intel Parallel Studio Home
A common question that routinely comes up is how to share data between forms.
I have outlined two common ways to pass data between forms, among many others. I have used a public property on the output form to accept a value and update the display. I also have a method accepting parameters from the input form, to update the display.
On the first form there are three textboxes tbFirstName, tbLastName, and tbSample with a Submit button to redirect to the output form. I have the same layout on the output form to display the passed values.
I have outlined two common ways to pass data between forms, among many others. I have used a public property on the output form to accept a value and update the display. I also have a method accepting parameters from the input form, to update the display.
On the first form there are three textboxes tbFirstName, tbLastName, and tbSample with a Submit button to redirect to the output form. I have the same layout on the output form to display the passed values.
public partial class frmInput : Form { public frmInput() { InitializeComponent(); } private void btnSubmit_Click(object sender, EventArgs e) { //Set our variables from our input form string firstName = this.tbFirstName.Text; string lastName = this.tbLastName.Text; string sample = this.tbSample.Text; //Create an instance of the output form frmOutput frmOut = new frmOutput(); //We set values through a property frmOut.Sample = sample; //We set values through a public method frmOut.SetDisplayValues(firstName, lastName); //We show the output form frmOut.ShowDialog(); } } public partial class frmOutput : Form { private string sample; //Getter / Setter for Sample public string Sample { get { return sample; } set { sample = value; //Set from property this.tbSample.Text = this.sample; } } public frmOutput() { InitializeComponent(); } public void SetDisplayValues(string firstName, string lastName) { //Set from method this.tbFirstName.Text = firstName; this.tbLastName.Text = lastName; } }
0
•
•
•
•
can you please help me.... what is the code in windows form...i want to open a new form and closing or hiding my current form....
Similar Threads
- Passing data from forms from one page to another (JavaScript / DHTML / AJAX)
- Passing Data Between Forms Help! (C#)
- Javascript: Passing Forms into Sub-routines (JavaScript / DHTML / AJAX)
- Passing Info Between Forms (Java)
- passing data between forms (Visual Basic 4 / 5 / 6)
| Thread Tools | Search this Thread |
.net access activedirectory advice applicatio array asp.net beginner broadcast buttons c# chat check collections combobox commerce connect content control custom database datetime dbconnection default deserialized development directrobot dll drawing dubai ecommerce enabled error exectuable file foreach form forms function game gdi+ http httpwebrequest if...loop index java javascript list listbox listview mailmerge mdd messagebox mono msword mysql news oracle password photoshop php post print problem programming radio read region remote remoting reporting resource richtextbox save saving smoobjects softwaredevelopment sql sql-server sqlserver stream stringformatting study taborder tcpclientchannel textbox totaldays treeview user vb vb.net view vistaflaw visual web whileloop windows winforms wordautomation wpf




