Results 1 to 6 of 6

Thread: Controlling another form's objects

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    8

    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?

  2. #2
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Cochin, India
    Posts
    350

    Re: Controlling another form's objects

    I had similar problem once
    read this
    http://vbforums.com/showthread.php?t=360293
    DOK OCK : "The power of .net in the palm of my hand, nothing will stand in my way. Nothing."

  3. #3
    Hyperactive Member
    Join Date
    Aug 2005
    Location
    Cochin, India
    Posts
    350

    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."

  4. #4
    Hyperactive Member
    Join Date
    Jul 2005
    Posts
    394

    Re: Controlling another form's objects

    Try using showDialog instead of show.
    VB Code:
    1. Dim frm as New myForm
    2. Dim result as DialogResult
    3.  
    4. result = frm.ShowDialog
    5.  
    6. If result = DialogResult.OK then
    7.     'Do something
    8. Else
    9.     'Do something else
    10. End If
    Just make sure that your secondary form returns a dialog result and this should do what you want.

  5. #5
    PowerPoster
    Join Date
    Aug 2005
    Location
    College Station, TX
    Posts
    4,521

    Re: Controlling another form's objects

    Or without modifying the constructor, by showing form2 as being owned by form1...
    VB Code:
    1. 'in Form1, when calling Form2
    2. Dim frm2 As New frm2()
    3. Me.AddOwnedForm(frm2)
    4. frm2.ShowDialog()
    5.  
    6. 'in form2
    7. Dim form1 As Form1 = DirectCast(Me.Owner, Form1) 'now you can refer to Form1's items!!
    8. Form1.MyProcedure() 'MyProcedure is sub on form1
    9. 'or
    10. Form1.TextBox1.Text = "MyText"
    11. 'etc...

  6. #6

    Thread Starter
    New Member
    Join Date
    Dec 2005
    Posts
    8

    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
  •  



Click Here to Expand Forum to Full Width