|
-
Dec 5th, 2005, 11:47 AM
#1
Thread Starter
New Member
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?
-
Dec 5th, 2005, 11:56 AM
#2
Hyperactive Member
Re: Controlling another form's objects
DOK OCK : "The power of .net in the palm of my hand, nothing will stand in my way. Nothing." 
-
Dec 5th, 2005, 11:58 AM
#3
Hyperactive Member
Re: Controlling another form's objects
we can remove directcast if sub new is:
Public Sub New(ByVal frmMain As Form1)
DOK OCK : "The power of .net in the palm of my hand, nothing will stand in my way. Nothing." 
-
Dec 5th, 2005, 12:11 PM
#4
Hyperactive Member
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.
-
Dec 5th, 2005, 12:11 PM
#5
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...
-
Dec 5th, 2005, 03:31 PM
#6
Thread Starter
New Member
Re: Controlling another form's objects
Awesome! Thank you all so much. I can't wait to get to lab to try it out.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|