Forms Talking to each other?
Hello everyone,
I am trying to get one of my forms (frm1) to show another form (frm2) and then wait until the a button is clicked in frm2 to continue with the following code in frm1.
Here is an example:
Dim var1 as Integer
Dim frm2 As New frm2
frm2.Show()
var1 = var2
I want to pass the value of var2 to var1 when I click a button. var2 comes from frm2. What is happens instead is,frm1 shows frm2 and continues on to the next line (var1=var2). Can anyone help?
Reply With Quote
Re: Forms Talking to each other?
Try the ShowDialog method
e.g.
That is a blocking call
Re: Forms Talking to each other?
Use ShowDialog so it stops processing on the first form until the second is closed.
Code:
Dim var1 as Integer
Dim frm2 As New frm2
frm2.ShowDialog()
var1 = var2
Re: Forms Talking to each other?
Remove var1 = var2 from the Form Load.
Presuming both are declared on Form1, make them Public variables. Then in your button on Form2, just do
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Form1.var1 = Form1.var2
End Sub
If var2 is declared on Form2, then remove the Form1 prefix from var2.
Re: Forms Talking to each other?
Thank you all for your help. I used showdialog() and that's exactly what I was looking for.
Re: Forms Talking to each other?
If you consider this resolved, you could help us out by pulling down the Thread Tools menu and clicking the Mark Thread Resolved menu item. That will let everyone know that you have your answer.
Thank you. :)
Re: Forms Talking to each other?
Hi,
How to pass TextBox values from one Form to Another
http://yulyos4vbnet.spaces.live.com/...2024!169.entry