Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. How to disable all control inside a form ?

How to disable all control inside a form ?

Scheduled Pinned Locked Moved Visual Basic
tutorialquestion
8 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    cheeken2u
    wrote on last edited by
    #1

    i have a window form consists around 30 textbox and label, so i don't want disable all by write code one by one , all any idea ? for example , using a for loop to detect all label and textbox and disable it?

    Regards, Chee ken

    C T C C 4 Replies Last reply
    0
    • C cheeken2u

      i have a window form consists around 30 textbox and label, so i don't want disable all by write code one by one , all any idea ? for example , using a for loop to detect all label and textbox and disable it?

      Regards, Chee ken

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      for each (Control control in Controls) control.Enabled = false end for I don't 'do' VB, the syntax may be off. However, there is a Controls collection in your form that you can foreach over.

      Christian Graus - Microsoft MVP - C++ Metal Musings - Rex and my new metal blog "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      1 Reply Last reply
      0
      • C cheeken2u

        i have a window form consists around 30 textbox and label, so i don't want disable all by write code one by one , all any idea ? for example , using a for loop to detect all label and textbox and disable it?

        Regards, Chee ken

        T Offline
        T Offline
        The ANZAC
        wrote on last edited by
        #3

        for each c as Control in me.controls if typeof c is textbox then 'for textbox you can put label or whatever other controls 'do actions (e.g. c.enabled = false) end if next

        Posted by The ANZAC

        C 1 Reply Last reply
        0
        • T The ANZAC

          for each c as Control in me.controls if typeof c is textbox then 'for textbox you can put label or whatever other controls 'do actions (e.g. c.enabled = false) end if next

          Posted by The ANZAC

          C Offline
          C Offline
          cheeken2u
          wrote on last edited by
          #4

          If Not cbYear.SelectedValue.Equals(Now.Year.ToString) Then ' Examine every control. For Each ctl As Control In Me.Controls If TypeOf ctl Is TextBox Then ctl.Enabled = False On Error GoTo 0 End If Next ctl Else For Each ctl As Control In Me.Controls If TypeOf ctl Is TextBox Then ctl.Enabled = True On Error GoTo 0 End If Next ctl End If cbYear is a combobox, why this code cannot work ? If i comment " If TypeOf ctl Is TextBox Then" then all control will disable. thanks

          Regards, Chee ken

          T 1 Reply Last reply
          0
          • C cheeken2u

            i have a window form consists around 30 textbox and label, so i don't want disable all by write code one by one , all any idea ? for example , using a for loop to detect all label and textbox and disable it?

            Regards, Chee ken

            C Offline
            C Offline
            Chatura Dilan
            wrote on last edited by
            #5

            or you can put them in a GroupBox and, set GroupBox's enable property to false

            Chatura Dilan

            M 1 Reply Last reply
            0
            • C Chatura Dilan

              or you can put them in a GroupBox and, set GroupBox's enable property to false

              Chatura Dilan

              M Offline
              M Offline
              MatrixCoder
              wrote on last edited by
              #6

              Same for a Panel.


              Trinity: Neo... nobody has ever done this before. Neo: That's why it's going to work.

              1 Reply Last reply
              0
              • C cheeken2u

                i have a window form consists around 30 textbox and label, so i don't want disable all by write code one by one , all any idea ? for example , using a for loop to detect all label and textbox and disable it?

                Regards, Chee ken

                C Offline
                C Offline
                cheeken2u
                wrote on last edited by
                #7

                Thanks for you all help!;)

                Regards, Chee ken

                1 Reply Last reply
                0
                • C cheeken2u

                  If Not cbYear.SelectedValue.Equals(Now.Year.ToString) Then ' Examine every control. For Each ctl As Control In Me.Controls If TypeOf ctl Is TextBox Then ctl.Enabled = False On Error GoTo 0 End If Next ctl Else For Each ctl As Control In Me.Controls If TypeOf ctl Is TextBox Then ctl.Enabled = True On Error GoTo 0 End If Next ctl End If cbYear is a combobox, why this code cannot work ? If i comment " If TypeOf ctl Is TextBox Then" then all control will disable. thanks

                  Regards, Chee ken

                  T Offline
                  T Offline
                  The ANZAC
                  wrote on last edited by
                  #8

                  because you need to change is Textbox to is Combobox.

                  Posted by The ANZAC

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups