1.11M Members

Disabling Buttons

 
0
 

So I have a main form and 5 other forms. When I press a button on the main form, I want it to open Form2 and disable a certain button in form2 so that it cannot be used. I produced this code but the button is still active and there is no effect. Please help.

 Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        My.Forms.Form2.SaveVISACaseButton.Enabled = False
        My.Forms.Form2.SaveVISACaseButton.Visible = False
        Dim form2 As New Form2
        My.Forms.Form2.SaveVISACaseButton.Enabled = False
        My.Forms.Form2.SaveVISACaseButton.Visible = False
        form2.Show()
        Me.Hide()

    End Sub
 
0
 

It appears to me that if Form2 is already designed that you won't need to Dim a new one just show the one you have.

 
1
 

Declare object instance of form2 and use it to disable or visble a button in form2.
You already declare it but you didn't use it.
Try this :

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim form2 As New Form2
    form2.SaveVISACaseButton.Enabled = False
    form2.SaveVISACaseButton.Visible = False
    form2.Show()
    Me.Hide()
End Sub
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article