Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Visual Basic 2008 change enabled state of all buttons on form

Posted on 2010-09-09
12
Medium Priority
?
467 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 1000 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
Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

 

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 1000 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

Setting up LaraDock for Laravel

Learn how to set up LaraDock in a Laravel project - LaraDock gives us an easy way to run a Laravel application using Docker in a single command.

Question has a verified solution.

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

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

715 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