Results 1 to 4 of 4

Thread: I feel like a n00b, but how do you ...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Oct 2007
    Posts
    258

    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:
    1. Dim ctl As Control = Me.GetNextControl(tbStudio, True)
    2.         Do Until ctl Is Nothing
    3.             If TypeOf ctl Is Button Then
    4.                 If ctl.Enabled Then
    5.                     ctl.Enabled = False
    6.                 Else
    7.                     ctl.Enabled = True
    8.                 End If
    9.             End If
    10.             ctl = Me.GetNextControl(ctl, True)
    11.         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!

  2. #2
    Fanatic Member Vectris's Avatar
    Join Date
    Dec 2008
    Location
    USA
    Posts
    941

    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.
    If your problem is solved, click the Thread Tools button at the top and mark your topic as Resolved!

    If someone helped you out, click the button on their post and leave them a comment to let them know they did a good job

    __________________
    My Vb.Net CodeBank Submissions:
    Microsoft Calculator Clone
    Custom TextBox Restrictions
    Get the Text inbetween HTML Tags (or two words)

  3. #3
    PowerPoster 2.0 Negative0's Avatar
    Join Date
    Jun 2000
    Location
    Southeastern MI
    Posts
    4,367

    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"

  4. #4
    Frenzied Member
    Join Date
    Dec 2007
    Posts
    1,072

    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
  •  



Click Here to Expand Forum to Full Width