How do pass a value from one Windows Form to another

  • Thread starter Thread starter Rodney
  • Start date Start date
R

Rodney

I need to pass a value from one TextBox on a Windows Form to another TextBox
on another Windows Form . I am rather new to VB.net and I am having
difficulty performing this task. Any help is greatly appreciated.
 
I need to pass a value from one TextBox on a Windows Form to another
TextBox
on another Windows Form . I am rather new to VB.net and I am having
difficulty performing this task. Any help is greatly appreciated.

Depending on how the forms are related:

If they both have a common parent:
Pass the parent as a parameter when you create Form1. Then when you need
to pass some value on to Form2, call a method on the parent and have the
parent forward the value to Form2.

If Form2 is the parent of Form1:
Same thing, pass Form2 as a parameter when creating Form1.
Unless you want to obtain the value of the textbox using Form1 as a popup
dialog. Then either make the textbox public (not recommended), or store
the content of the textbox in a public variable on Form1, or make a
property on Form1 that will give the value of the textbox (recommended)
 
Check out following article:
http://msdn.microsoft.com/library/en-us/dv_vstechart/html/vbtchworkingwithmu
ltipleformsinvisualbasicnetupgradingtonet.asp

Working with Multiple Forms in Visual Basic .NET: Upgrading to .NET
Describes how working with multiple forms has changed from previous editions
of Microsoft Visual Basic and illustrates several key techniques, including
displaying a second form, changing the appearance of another form, and using
a form as a dialog. (8 printed pages)
--
Greetz

Jan Tielens
________________________________
Read my weblog: http://weblogs.asp.net/jan
 
I guess this is more a forms or vb newsgroup thread, but the important
concept here is that you should view forms as just another type of class. So
ideally you should create a public property on your form to set either a
form level variable or the text box, so that your form is encapsulated and
you can use it as an object anywhere in your system.

James
 
Back
Top