Have button enabled when coming from a certain form
Good day
Quick question, I want to have a button on a form disabled when the user comes from one path, but enabled when they come from a different path.
Example being the button (Button1) is on Form4, so when the user moves from Form3 to Form4, then Button1 is disabled. But if the user comes from Form6 to Form4 then Button1 is enabled.
I have googled this and looked around this site to find anything close to this, but have had no luck. I have no clue on how the code would look.
Thanks
Re: Have button enabled when coming from a certain form
Are we talking standard application or MDI?
Re: Have button enabled when coming from a certain form
if any button on form4 causes you to navigate to another form then i would tell them to make button1 disabled. I would then have form6 (or other forms) make it enabled when you navigate back to form4.
Is that any use to you or do you want example code?
Re: Have button enabled when coming from a certain form
Put a public sub on the form that has the button. The sub would enable the button (or you could have it take a Boolean argument and either enable or disable based on that argument). Then, call the method just before you show the form.
Re: Have button enabled when coming from a certain form
Quote:
Originally Posted by
sico
if any button on form4 causes you to navigate to another form then i would tell them to make button1 disabled. I would then have form6 (or other forms) make it enabled when you navigate back to form4.
Is that any use to you or do you want example code?
an example code would be benificial
Re: Have button enabled when coming from a certain form
On your Form3, any time you call Form4, try something like this:
Code:
Form4.Button1.Enabled = False
Form4.Show
Re: Have button enabled when coming from a certain form
Public Class Form4
Private Sub ButtontoForm3_Click() Handles ButtontoForm3.Click
Button1.Enabled = False
Form3.show()
End Sub
End Class
---------------
Public Class Form6
Private Sub ButtontoForm4_Click() Handles ButtontoForm4.Click
Form4.Button1.Enabled = True
Form4.show()
End Sub
End Class
There may be easier ways, depending on the number of Forms you want to Enable it and Disable it, but this is A method that should work.
Re: Have button enabled when coming from a certain form
Personally, I would add a constructor to Form4 with a Boolean parameter and make that the only constructor, so the only way to create an instance of Form4 is to invoke that and pass a Boolean. You then use that Boolean inside the constructor to enable or disable the Button, e.g.
Code:
Public Class Form4
Public Sub New(enableButton As Boolean)
InitializeComponent()
Button1.Enabled = enableButton
End Sub
'...
End Class
You'd then display a Form4 instance like this:
Code:
Dim f4 As New Form4(True)
f4.Show()
That will display with the Button enabled or you can pass False to disable it.
Re: Have button enabled when coming from a certain form
Quote:
Originally Posted by
sico
Public Class Form4
Private Sub ButtontoForm3_Click() Handles ButtontoForm3.Click
Button1.Enabled = False
Form3.show()
End Sub
End Class
---------------
Public Class Form6
Private Sub ButtontoForm4_Click() Handles ButtontoForm4.Click
Form4.Button1.Enabled = True
Form4.show()
End Sub
End Class
There may be easier ways, depending on the number of Forms you want to Enable it and Disable it, but this is A method that should work.
I was nnot able to get it to work. I have it disabled, but when coming from form6 to form4 it wont enable
Re: Have button enabled when coming from a certain form
Ignore what I just said, minor typo on my part. I was able to get it to work. Thanks for all the help, really appreciate it!