-
Dec 4th, 2012, 12:58 PM
#1
Thread Starter
New Member
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
-
Dec 4th, 2012, 03:56 PM
#2
Re: Have button enabled when coming from a certain form
Are we talking standard application or MDI?
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Dec 4th, 2012, 04:58 PM
#3
Junior Member
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?
-
Dec 4th, 2012, 05:30 PM
#4
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.
My usual boring signature: Nothing
-
Dec 4th, 2012, 05:49 PM
#5
Thread Starter
New Member
Re: Have button enabled when coming from a certain form
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
-
Dec 4th, 2012, 06:01 PM
#6
Hyperactive Member
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
-
Dec 4th, 2012, 06:04 PM
#7
Junior Member
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.
-
Dec 4th, 2012, 06:10 PM
#8
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.
-
Dec 4th, 2012, 06:34 PM
#9
Thread Starter
New Member
Re: Have button enabled when coming from a certain form
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
-
Dec 4th, 2012, 06:42 PM
#10
Thread Starter
New Member
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!
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
|