affecting events in one form from another form... Is this possible?

vis781

Well-known member
Joined
Aug 30, 2005
Messages
2,016
Location
Cambridge, UK
Programming Experience
5-10
Hi here is the basics about what i am trying to do. I have a form open, say we'll call it form1, on it is three textboxes. Now, what i would like to do is to open another form with another three textboxes on it, but when i put text into these textboxes, the text automatically appears in the textboxes on the other form aswell in real time. Is this even possible? or am i in some sort of a dream world?!!??
 
You can find many ways to accomplish certain task. however this is the one.
Well, all you need to do is to get text property of textBox in the second form

VB.NET:
[size=2][color=#0000ff]Public [/color][/size][size=2][color=#0000ff]ReadOnly [/color][/size][size=2][color=#0000ff]Property[/color][/size][size=2] UserName() [/size][size=2][color=#0000ff]As [/color][/size][size=2][color=#0000ff]String
 
[/color][/size][size=2][color=#0000ff]Get
 
[/color][/size][size=2][color=#0000ff]Return[/color][/size][size=2] txtFromForm2.Text 'i assumed your textBox is named so
 
[/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Get
 
[/color][/size][size=2][color=#0000ff]End [/color][/size][size=2][color=#0000ff]Property
 
[/color][/size]

this is code that you need to join inside first form ... for example:

VB.NET:
[size=2][color=#0000ff]Private[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub[/color][/size][size=2] Button1_Click([/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] sender [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.Object, [/size][size=2][color=#0000ff]ByVal[/color][/size][size=2] e [/size][size=2][color=#0000ff]As[/color][/size][size=2] System.EventArgs) [/size][size=2][color=#0000ff]Handles[/color][/size][size=2] Button1.Click
[/size][size=2][color=#0000ff]Dim[/color][/size][size=2] f2 [/size][size=2][color=#0000ff]As[/color][/size][size=2] [/size][size=2][color=#0000ff]New[/color][/size][size=2] Form2

f2.ShowDialog([/size][size=2][color=#0000ff]Me[/color][/size][size=2]) [/size][size=2][color=#008000]' Show Form2

[/color][/size][size=2][/size][size=2][color=#0000ff]Me[/color][/size][size=2].txtForm1.Text = f2.UserName [color=green]'note that userName is property that we created within form2[/color]

[/size][size=2][color=#0000ff]End[/color][/size][size=2] [/size][size=2][color=#0000ff]Sub

[/color][/size]

Regards ;)
 
vis781 -

kulrom's code will indeed beam the text from one form to the other. BUT, from your description I surmise that you have some data (the text in these fields) that "wants" to be stored in a data structure independent from the specific form(s). That is, a simple model/view relationship: the data lives in an object (the model) and is displayed and edited with one or multiple forms (the views). So rather than passing data from box to box or form to form, all the forms "look at" an object that holds the data. Make sense?
 
Back
Top