Controlling another form's objects
I'm writing an application in VB .NET 2003 that has a dialog box. I'm trying to create an event procedure that changes the Text property of various labels on my main form when I click a button on my dialog box. I have been searching for a way to do this for over a week. Can anyone help?
Re: Controlling another form's objects
Re: Controlling another form's objects
we can remove directcast if sub new is:
Public Sub New(ByVal frmMain As Form1)
Re: Controlling another form's objects
Try using showDialog instead of show.
VB Code:
Dim frm as New myForm
Dim result as DialogResult
result = frm.ShowDialog
If result = DialogResult.OK then
'Do something
Else
'Do something else
End If
Just make sure that your secondary form returns a dialog result and this should do what you want.
Re: Controlling another form's objects
Or without modifying the constructor, by showing form2 as being owned by form1...
VB Code:
'in Form1, when calling Form2
Dim frm2 As New frm2()
Me.AddOwnedForm(frm2)
frm2.ShowDialog()
'in form2
Dim form1 As Form1 = DirectCast(Me.Owner, Form1) 'now you can refer to Form1's items!!
Form1.MyProcedure() 'MyProcedure is sub on form1
'or
Form1.TextBox1.Text = "MyText"
'etc...
Re: Controlling another form's objects
Awesome! Thank you all so much. I can't wait to get to lab to try it out.