|
-
Mar 10th, 2009, 09:49 PM
#1
Thread Starter
Hyperactive Member
I feel like a n00b, but how do you ...
Alright, I have form, with multiple buttons on it.
I want it so when I Click on the Button that Says START it will Change to STOP but at the same time Enable all the Disabled Buttons on the Form. ATM I have this.
vb Code:
Dim ctl As Control = Me.GetNextControl(tbStudio, True)
Do Until ctl Is Nothing
If TypeOf ctl Is Button Then
If ctl.Enabled Then
ctl.Enabled = False
Else
ctl.Enabled = True
End If
End If
ctl = Me.GetNextControl(ctl, True)
Loop
Works Good, but when I add the btnStartStop.Text = "Start" or .Text = "Stop" to the If Statements, it's always getting stuck on "Stop"
I also tried a Boolean statement but came out all funky, EVERY OTHER button was Disabled while the OTHERS were Enabled.
I feel like a n00b, I've been programing for a bit now, but just got back into it, Help!
-
Mar 10th, 2009, 10:03 PM
#2
Re: I feel like a n00b, but how do you ...
You should use a For loop to go through all the controls, it works better.
Code:
For each ctrl as Control in Controls
If TypeOf ctrl Is Button and ctrl.Enabled = False then ctrl.Enabled = True
Next
btnStartStop.Text = "Stop"
That's all you need. Also you said you only want to enable buttons already disabled, but your code also shows that you are disabling buttons that are enabled, which you didn't state.
-
Mar 10th, 2009, 10:08 PM
#3
Re: I feel like a n00b, but how do you ...
Actually Vectris, your code will only work if there are no nested controls on the form (think panels and tabpages). Wesley's code will work with any level of nesting.
As to Wesley's question, can you show us the code for what you mean by this:
but when I add the btnStartStop.Text = "Start" or .Text = "Stop" to the If Statements, it's always getting stuck on "Stop"
-
Mar 10th, 2009, 10:12 PM
#4
Frenzied Member
Re: I feel like a n00b, but how do you ...
This is a little off-focus, but I recommend you replace this code:
Code:
If ctl.Enabled Then
ctl.Enabled = False
Else
ctl.Enabled = True
End If
With:
Code:
ctl.Enabled = Not ctl.Enabled
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
|