Link to home
Start Free TrialLog in
Avatar of CTEC
CTEC

asked on

Visual Basic 2008 change enabled state of all buttons on form

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.,
Avatar of ghayasurrehman
ghayasurrehman
Flag of Pakistan image

add all button in groupbox or panel
then use groupbox.enable = false
or panel.enable = false
SOLUTION
Avatar of FactorB
FactorB

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CTEC
CTEC

ASKER

Thanks,

It syas:
Type 'CommandButton' is not defined
Change it simply to Button
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

ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CTEC

ASKER

Thanks,

how would i call that?

SetButtons(Button, Enabled)  ?
Avatar of CTEC

ASKER

sorry just read it again and it says :)
From within the Form, you would do:

   SetButtons(Me, True) ' Enable them all

Or:

   SetButtons(Me, False) ' Disable them all
Good luck!....  =)