Question windows form control status read

chrisb

Member
Joined
Oct 12, 2012
Messages
10
Programming Experience
Beginner
Hi

I am new to vb.net programming and I want to read form controls(button,text box..) status and turn visible status to off and finally restore to original status after processing.


thanks
 
Hi,

To demonstrate accessing controls on a form create a new form, add a Button, Textbox, Label, Listbox and Listview and then copy the code below to the code behind the Button and run. Click the button numerous times and you will see the controls disappear and appear.

VB.NET:
Public Class Form1
 
  Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    For Each ctrl As Control In Me.Controls
      Select Case ctrl.GetType
        Case GetType(TextBox)
          Dim myCurrentControl As TextBox = CType(ctrl, TextBox)
          myCurrentControl.Visible = Not myCurrentControl.Visible
        Case GetType(Label)
          Dim myCurrentControl As Label = CType(ctrl, Label)
          myCurrentControl.Visible = Not myCurrentControl.Visible
        Case GetType(ListBox)
          Dim myCurrentControl As ListBox = CType(ctrl, ListBox)
          myCurrentControl.Visible = Not myCurrentControl.Visible
        Case GetType(ListView)
          Dim myCurrentControl As ListView = CType(ctrl, ListView)
          myCurrentControl.Visible = Not myCurrentControl.Visible
        Case Else
          'Case GetType(etc)
      End Select
    Next
  End Sub
End Class
Please do post back if you have difficulty understanding the code.

Good Luck and cheers,

Ian
 
A quick way to disable all controls while processing is to set the forms Enabled property to False.
 
Can you provide a more detailed description of what you're trying to achieve because there is almost certainly a better way? It may be as simple as calling ShowDialog on a form instead of Show, which is quite a common one, but we won't know for sure unless we know more of the circumstances.
 
I tried by reading status of control status and added status it to a listbox. Finally restored the control status from listbox. this works the way i wanted.

thanks for your reply
 
Back
Top