Solved

Visual Basic 2008 change enabled state of all buttons on form

Posted on 2010-09-09
12
466 Views
Last Modified: 2012-08-13
Hi,

I have an application in Visual Basic 2008 where there is a form with lots of buttons on.
Is there a way to control the Enabled state of all the buttons on the form?
I.e. Form1.AllButtons.Enabled = True?


Thanks

Daniel.,
0
Comment
Question by:CTEC
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 3
  • +1
12 Comments
 
LVL 3

Expert Comment

by:ghayasurrehman
ID: 33640800
add all button in groupbox or panel
0
 
LVL 3

Expert Comment

by:ghayasurrehman
ID: 33640820
then use groupbox.enable = false
or panel.enable = false
0
 
LVL 6

Assisted Solution

by:FactorB
FactorB earned 250 total points
ID: 33640838
Simple disable or enable command buttons or buttons ... change commandbutton to button..

Private Sub Disable_Controls()
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is CommandButton then ctrl.Enabled = False
Next
End Sub

Private Sub Enable_Controls()
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is CommandButton then ctrl.Enabled = True
Next
End Sub

I didn't had a time to check it...

Regards,
B.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:CTEC
ID: 33640911
Thanks,

It syas:
Type 'CommandButton' is not defined
0
 
LVL 6

Expert Comment

by:FactorB
ID: 33640950
Change it simply to Button
0
 
LVL 3

Expert Comment

by:ghayasurrehman
ID: 33640966
use panel or groupbox instead of parsing the controls, that will be more efficient

or use


Private Sub Disable_Controls()
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is Button then ctrl.Enabled = False
Next
End Sub

Private Sub Enable_Controls()
Dim ctrl As Control
For Each ctrl In Me.Controls
If TypeOf ctrl Is Button then ctrl.Enabled = True
Next
End Sub

Open in new window

0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 250 total points
ID: 33641015
That won't catch the Buttons if they are INSIDE a different container (than the form itself) or if they are in multiple containers...

...what is needed is a RECURSIVE method:

    SetButtons(Me, False)
    ' < or >
    SetButtons(Me, True)

Using this code:
    Private Sub SetButtons(ByVal cont As Control, ByVal EnabledState As Boolean)
        For Each ctl As Control In cont.Controls
            If TypeOf ctl Is Button Then
                ctl.Enabled = EnabledState
            ElseIf ctl.HasChildren Then
                SetButtons(ctl, EnabledState)
            End If
        Next
    End Sub

Open in new window

0
 

Author Comment

by:CTEC
ID: 33641060
Thanks,

how would i call that?

SetButtons(Button, Enabled)  ?
0
 

Author Comment

by:CTEC
ID: 33641065
sorry just read it again and it says :)
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 33641074
From within the Form, you would do:

   SetButtons(Me, True) ' Enable them all

Or:

   SetButtons(Me, False) ' Disable them all
0
 
LVL 86

Expert Comment

by:Mike Tomlinson
ID: 33641084
Good luck!....  =)
0

Featured Post

[Live Webinar] The Cloud Skills Gap

As Cloud technologies come of age, business leaders grapple with the impact it has on their team's skills and the gap associated with the use of a cloud platform.

Join experts from 451 Research and Concerto Cloud Services on July 27th where we will examine fact and fiction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question