| | |
Passing data between forms
Please support our C# advertiser: Programming Forums - DaniWeb Sister Site
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 |
Tag cloud for c#, forms
.net access ado.net ajax analyst applicaions array asp asp.net association associations basic beginner buttons c# casting chat check checkbox combobox contorl convert cookies cs4 data database datagridview datetime dba development disabled drawing dynamically e-commerce enum eventhandlers excel file files forloop form forms gdi+ grid http httpwebrequest image index inline java javascript label linkedlist lisp list listbox location login math mysql notepad object odp.net operator oracle panel photoshop php picturebox platform post programmer programming redirect remote remoting resource resourcefile richtextbox robot saving sql sql-server ssh storing string table tables textbox treeview usercontrol validation visual-studio visualbasic web webbrowser windows winforms wpf write




