|
-
Oct 27th, 2002, 03:58 PM
#1
Thread Starter
Junior Member
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
-
Oct 27th, 2002, 06:08 PM
#2
PowerPoster
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
-
Oct 27th, 2002, 06:29 PM
#3
Thread Starter
Junior Member
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
-
Oct 27th, 2002, 11:03 PM
#4
PowerPoster
Try this:
VB Code:
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
Private Sub ButtonCloseFormCardDesign_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ButtonCloseFormCardDesign.Click
Dim frm As FormMain 'Or what ever your main forms name is
frm = Me.ParentForm
frm.Button1.Enabled = True
Me.Close()
End Sub
-
Oct 28th, 2002, 07:37 AM
#5
Thread Starter
Junior Member
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
-
Oct 28th, 2002, 09:31 AM
#6
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|