|
-
Apr 26th, 2008, 05:56 PM
#1
Thread Starter
Hyperactive Member
[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?
Last edited by bagstoper; Apr 26th, 2008 at 06:41 PM.
-
Apr 26th, 2008, 07:02 PM
#2
PowerPoster
Re: [2005] component array
control arrays dont exist in .NET
-
Apr 26th, 2008, 07:03 PM
#3
Thread Starter
Hyperactive Member
Re: [2005] component array
Dang. now i am sad. is there any way to work around that?
-
Apr 26th, 2008, 07:45 PM
#4
PowerPoster
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
Last edited by BrailleSchool; Apr 26th, 2008 at 07:55 PM.
-
Apr 26th, 2008, 08:08 PM
#5
Thread Starter
Hyperactive Member
Re: [2005] component array
Ok, that will work for what i am wanting to do thanks so much for your help. (rated you)
-
Apr 26th, 2008, 10:01 PM
#6
PowerPoster
Re: [2005] component array
youre welcome. please resolve thread if youve found your resolution.
-
May 8th, 2008, 02:17 PM
#7
Addicted Member
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
-
May 9th, 2008, 10:30 PM
#8
PowerPoster
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
-
May 9th, 2008, 10:32 PM
#9
PowerPoster
Re: [RESOLVED] [2005] component array
youre trying to do a control array and they dont exist in .NET
 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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|