Results 1 to 6 of 6

Thread: Manipulate a button on another form

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    20

    Manipulate a button on another form

    Hello,

    I am trying to change the properties of a button on form1 from form2. The button on form1 is a toolbar button. When it is pressed, I have it set to "ButtonToolbarNew.Enabled = False", to disable it. I want to be able to re-enable it when a different button on another form, form2, is pressed.

    Thanks again!
    Kosta

  2. #2
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    You going to have to have a reference to the other form in order to do that.

    See this post to get you started:
    http://www.vbforums.com/showthread.p...orm+properties

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    20
    Hi,

    I had read through those posts and tried:

    Code:
    'on FormMain
    'on this form, when ButtonToolbarNew is clicked it opens FormCardDesign and also sets ButtonToolbarNew to Enabled = False
        Private Sub ButtonToolbarNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonToolbarNew.Click
            Dim frm As New FormCardDesign()
            frm.MdiParent = Me
            frm.Show()
            ButtonToolbarNew.Enabled = False
        End Sub
    
    '---------------------------------------------
    
    'on FormCardDesign
    'on this form, when ButtonCloseFormCardDesign is clicked it closes FormCardDesign and also sets ButtonToolbarNew to Enabled = True
        Private Sub ButtonCloseFormCardDesign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCloseFormCardDesign.Click
            Me.Close()
            Dim frm As New FormMain()
            frm.ButtonToolbarNew.Enabled = True
        End Sub
    The problem is that nothing happens... ButtonCloseFormCardDesign is still set to Enabled = False. What am I missing?

    By the way, FormCardDesign is a MdiChild with FormMain as its MdiParent if that makes a difference. Also, ButtonToolbarNew is not a true toolbar button, but just a regular form button.


    Thanks,
    Kosta

  4. #4
    PowerPoster hellswraith's Avatar
    Join Date
    Jul 2002
    Location
    Washington St.
    Posts
    2,464
    Try this:
    VB Code:
    1. Private Sub ButtonToolbarNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonToolbarNew.Click
    2.         Dim frm As New FormCardDesign()
    3.         frm.MdiParent = Me
    4.         frm.Show()
    5.         ButtonToolbarNew.Enabled = False
    6.     End Sub
    7.  
    8.  
    9.  
    10.     Private Sub ButtonCloseFormCardDesign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCloseFormCardDesign.Click
    11.         Dim frm As FormMain 'Or what ever your main forms name is
    12.         frm = Me.ParentForm
    13.         frm.Button1.Enabled = True
    14.         Me.Close()
    15.     End Sub

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Oct 2002
    Posts
    20
    Thanks so much! It works perfectly!

    I added a frm.Dock = DockStyle.Top to ButtonToolbarNew_Click to make sure the form doesn't keep opening up one step lower and to the right on the screen each time it opens, and it looks great...

    Thanks again!
    Kosta

  6. #6
    Lively Member
    Join Date
    Jan 2002
    Location
    Malaysia
    Posts
    64
    Something you might also want to try out is to keep a permanent reference on the 2nd form to the main form. This way it's much easier to refer to the main form.

    Code:
    Private Sub ButtonToolbarNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonToolbarNew.Click
            Dim frm As New FormCardDesign()
            frm.MainForm = me 'in the second form declare a Dim MainForm as FormMain
            frm.Show()
            ButtonToolbarNew.Enabled = False
    End Sub
    
    Private Sub ButtonCloseFormCardDesign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCloseFormCardDesign.Click
            Me.MainForm.Button1.Enabled = True 'see how much less code you need to do here
            Me.Close()
    End Sub

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