Windows Develop Bookmark and Share   
 index > Windows Forms Designer > Passing Values between multiple forms
 

Passing Values between multiple forms

Ok i am tryin to build a simple application in VB.Net 2003

in that i have 3 forms say form1, form2 and form3

what i want is to accept a value in form1 using a text box

and send it to form2 and display it using a label

and using a command button load form3 which has closing code for all the forms

can you tell me how do i pass the values between the forms?

Thanx

Devendra Shangari  Friday, February 29, 2008 6:22 PM

Several ways to do it.

But if you want to do it easily

Create public methods on the forms that each can call to pass the value.

Also, in your main form(form 1) create instances(using variables) to display form 2/3.

Then you use the variables.method(passstringhere) or whatever you want to pass.

If you want form 2/3 to pass stuff to Form1, then have a property on form2/3 where you set the parent(which would be a ref to form 1 (me))

And have it call a method on it's parent to set values in form1.

Remember forms are just classes, treat them (almost) no different.

You can also create events etc on the forms, use your variable instances to raise the events passing it values etc.

Anokneemous  Saturday, March 01, 2008 7:36 PM

A simple solution I use often is to createa static "state" class and share it between the forms. The class doesn't need to be much more than a wrapper for a Dictionary, or Hashtable. You can then pass values between the forms by simply adding state values to the class in one form and reference them by key in another.
jlitfin  Monday, March 03, 2008 5:36 PM

Usinga public class and expose public fields as global variable like c++.

jsj_Samson  Tuesday, March 04, 2008 8:50 AM

You can use google to search for other answers

Custom Search

More Threads

• Form Designer does not load. How to solve?
• Fixed pixel based Fonts are shown bigger in 120 DPI
• Design Time Reflection
• serial port programing problem
• default values for inherited control
• Treeview adding nodes problem in Framework 2
• Splitter control on event
• help with usercontrol
• Create a new ControlCollection in a Form in c#
• Design-time error E_UNEXPECTED trying to connect to Access database