Du laver et array af en type som både har Visible property og ar parent klasse til de instantierede klasser og assigner referancer til alle dine objekter over i det array.
Så kan du loope.
Lidt abstrakt svar men der er ikke så mange oplysninger at bygge på.
Her er et gæt - prøv og kør det og kig lidt på det:
Imports System Imports System.Drawing Imports System.Windows.Forms Namespace MyFormProject
Class MainForm Inherits Form Private txtbx As TextBox Private cmbbx As ComboBox Private chkbx As CheckBox Private all As Control() Private btn As Button
Public Sub New() txtbx = New TextBox txtbx.Location = New Point (100, 100) cmbbx = New ComboBox cmbbx.Location = New Point (100, 200) cmbbx.Items.Add("aaa") cmbbx.Items.Add("bbb") cmbbx.Items.Add("ccc") chkbx = New CheckBox chkbx.Location = New Point (100, 300) all = New Control(2) {txtbx, cmbbx, chkbx} btn = New Button btn.Text = "Toggle visibility" btn.Location = New Point (225, 300) btn.Size = New Size (150, 25) AddHandler btn.Click, AddressOf ClickHandler ClientSize = New Size (400, 400) Controls.Add(txtbx) Controls.Add(cmbbx) Controls.Add(chkbx) Controls.Add(btn) Text = "Visibility test" End Sub
Private Sub ClickHandler(ByVal o As Object, ByVal e As EventArgs) Dim i As Integer For i = 0 to all.Length-1 all(i).Visible = Not all(i).Visible Next End Sub
<STAThread()> _ Public Shared Sub Main(ByVal args As String()) Application.Run(New MainForm ) End Sub End Class End Namespace
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.