[RESOLVED] [2005] component array
how do i set up an object array in VS 2005? i have tried naming two objects the same thing but it gives me an error saying that the namespace is already being used. i need to set up an array of picture boxes if that helps any. they all need to have the same name (imgSnake+array #(like imgSnake0))
anyone know what to do?
Re: [2005] component array
control arrays dont exist in .NET
Re: [2005] component array
Dang. now i am sad. is there any way to work around that?
Re: [2005] component array
yes, but each control has to have its own name. lets say you wanted to make an array of groupboxes and then wanted to cycle through them, you would do the following:
vb Code:
'make the array
Private arrGroupBoxes() As GroupBox
'initial index start for the array
Private intIndex As Index = 0
then in the form load (as an example), you would add the relevant group boxes by name to the array
vb Code:
'add the elements to the array by name
arrGroupBoxes = New GroupBox() {groupbox1, groupbox2, groupbox3}
then if you wanted to use a button to go forward and nother to go back, you do this:
vb Code:
Private Sub cmdBack_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdBack.Click
'make the group boxes invisible
arrGroupBoxes(intIndex).Visible = False
'decrease
intIndex -= 1
With arrGroupBoxes(intIndex)
'do something
End With
End Sub
vb Code:
Private Sub cmdNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdNext.Click
'make the group boxes invisible
arrGroupBoxes(intIndex).Visible = False
'increase
intIndex += 1
With arrGroupBoxes(intIndex)
'do something
End With
End Sub
Re: [2005] component array
Ok, that will work for what i am wanting to do thanks so much for your help. (rated you)
Re: [2005] component array
youre welcome. please resolve thread if youve found your resolution.
Re: [RESOLVED] [2005] component array
I'm trying to do the same thing but with check boxes. I followed the script, and I'm having trouble trying to get the check boxes to become visible. What am I missing here?
Code:
Imports Toub.Sound.Midi
Public Class Form1
Private chekbox(10) As CheckBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For i = 1 To 10
chekbox(i) = New CheckBox()
chekbox(i).Visible = True
chekbox(i).Left = i
chekbox(i).Top = i
Next
End Sub
End Class
Re: [RESOLVED] [2005] component array
if you already have the checkboxes on the form and you want to make them all visible with a mouse click of a button, you could do something like:
vb Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For Each ctrl As Control In Me.Controls
If TypeOf ctrl is CheckBox Then
me.ctrl.visible=True
End If
Next ctrl
End Sub
Re: [RESOLVED] [2005] component array
youre trying to do a control array and they dont exist in .NET
Quote:
Originally Posted by MotoMan_Yz400
I'm trying to do the same thing but with check boxes. I followed the script, and I'm having trouble trying to get the check boxes to become visible. What am I missing here?
Code:
Imports Toub.Sound.Midi
Public Class Form1
Private chekbox(10) As CheckBox
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
For i = 1 To 10
chekbox(i) = New CheckBox()
chekbox(i).Visible = True
chekbox(i).Left = i
chekbox(i).Top = i
Next
End Sub
End Class