|
|
|
date: Fri, 8 Feb 2008 00:06:00 -0800,
group: microsoft.public.dotnet.academic
back
Re: Indexing Controls
OK, I am now able to get a list of the controls and their associated index,
like so:
Dim strPics(16) As String 'a list of the picture boxes names
Dim intX As Integer 'used with For-Next loops
Private Sub frmMemEx_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim intNumItems As Integer
Dim strItemName As String
'create a list of the picture box names
For intX = 1 To 16
strPics(intX) = "pb" & Trim(Int((intX - 1) / 4) + 1)
If Int(intX Mod 4) = 0 Then
strPics(intX) = strPics(intX) & "4"
Else
strPics(intX) = strPics(intX) & Trim(intX - Int(intX / 4) * 4)
End If
Debug.Print(strPics(intX))
Next
intNumItems = Me.Controls.Count
For intX = 0 To intNumItems - 1
strItemName = Me.Controls.Item(intX).Name
If strItemName <> "cmdReset" Then ' don't access the reset button
'-- need to set pictureBox image here ---
End If
Next
However, I need to know how to assign and image from the image list to the
right picture box. I can already do this using the names likes so:
pb11.Image = imlPics.Images(8) 'set to blank display
pb12.Image = imlPics.Images(8) 'set to blank display
pb13.Image = imlPics.Images(8) 'set to blank display
pb14.Image = imlPics.Images(8) 'set to blank display
pb21.Image = imlPics.Images(8) 'set to blank display
pb22.Image = imlPics.Images(8) 'set to blank display
pb23.Image = imlPics.Images(8) 'set to blank display
pb24.Image = imlPics.Images(8) 'set to blank display
pb31.Image = imlPics.Images(8) 'set to blank display
pb32.Image = imlPics.Images(8) 'set to blank display
pb33.Image = imlPics.Images(8) 'set to blank display
pb34.Image = imlPics.Images(8) 'set to blank display
pb41.Image = imlPics.Images(8) 'set to blank display
pb42.Image = imlPics.Images(8) 'set to blank display
pb43.Image = imlPics.Images(8) 'set to blank display
pb44.Image = imlPics.Images(8) 'set to blank display
Me.Refresh()
But, this code can get exremely redundant. For now, I'm having my students
enter these redundant lines, but I'd like to show them how to do the same
tasks via a clever algorithm. The algorithm's no problem for me; I just need
to know how to assign the Image property using the control's index.
Thanks for all the help.
-------------------------------------------
"PvdG42" wrote:
> "danbug" wrote in message
> news:F3B1D815-998A-40F7-AAF5-B9581E7D063D@microsoft.com...
> >I have a form with about 16 pictureboxes on it. I would like to access
> >these
> > as an indexed array or something similar.
> > You'd think they'd simply put an index number on each form object, so one
> > could reference me.indexNum. I just need a way to scroll through the
> > objects
> > without having to create several lines of code for each one.
> >
> > TIA
>
>
> You don't say which language you're using, or which version of Visual
> Studio, but perhaps these articles will lead you in the right direction:
>
> http://msdn2.microsoft.com/en-us/library/7e4daa9c(VS.80).aspx
> (note the link: "ControlCollection class")
>
> http://msdn2.microsoft.com/en-us/library/system.windows.forms.control.controlcollection(VS.80).aspx
>
>
date: Sat, 9 Feb 2008 13:50:00 -0800
author: danbug
Re: Indexing Controls
"danbug" wrote in message
news:24F3EACE-8A63-400A-9E4F-6CCF83CD7D10@microsoft.com...
> OK, I am now able to get a list of the controls and their associated
> index,
> like so:
>
> Dim strPics(16) As String 'a list of the picture boxes names
> Dim intX As Integer 'used with For-Next loops
>
> Private Sub frmMemEx_Load(ByVal sender As System.Object, ByVal e As
> System.EventArgs) Handles MyBase.Load
>
> Dim intNumItems As Integer
> Dim strItemName As String
>
> 'create a list of the picture box names
> For intX = 1 To 16
> strPics(intX) = "pb" & Trim(Int((intX - 1) / 4) + 1)
> If Int(intX Mod 4) = 0 Then
> strPics(intX) = strPics(intX) & "4"
> Else
> strPics(intX) = strPics(intX) & Trim(intX - Int(intX / 4) *
> 4)
> End If
> Debug.Print(strPics(intX))
> Next
>
> intNumItems = Me.Controls.Count
>
> For intX = 0 To intNumItems - 1
> strItemName = Me.Controls.Item(intX).Name
> If strItemName <> "cmdReset" Then ' don't access the reset
> button
> '-- need to set pictureBox image here ---
> End If
> Next
>
> However, I need to know how to assign and image from the image list to the
> right picture box. I can already do this using the names likes so:
>
> pb11.Image = imlPics.Images(8) 'set to blank display
> pb12.Image = imlPics.Images(8) 'set to blank display
> pb13.Image = imlPics.Images(8) 'set to blank display
> pb14.Image = imlPics.Images(8) 'set to blank display
> pb21.Image = imlPics.Images(8) 'set to blank display
> pb22.Image = imlPics.Images(8) 'set to blank display
> pb23.Image = imlPics.Images(8) 'set to blank display
> pb24.Image = imlPics.Images(8) 'set to blank display
> pb31.Image = imlPics.Images(8) 'set to blank display
> pb32.Image = imlPics.Images(8) 'set to blank display
> pb33.Image = imlPics.Images(8) 'set to blank display
> pb34.Image = imlPics.Images(8) 'set to blank display
> pb41.Image = imlPics.Images(8) 'set to blank display
> pb42.Image = imlPics.Images(8) 'set to blank display
> pb43.Image = imlPics.Images(8) 'set to blank display
> pb44.Image = imlPics.Images(8) 'set to blank display
> Me.Refresh()
>
> But, this code can get exremely redundant. For now, I'm having my
> students
> enter these redundant lines, but I'd like to show them how to do the same
> tasks via a clever algorithm. The algorithm's no problem for me; I just
> need
> to know how to assign the Image property using the control's index.
>
> Thanks for all the help.
>
For these kinds of code specifics, I'd suggest that you post your question
in the group dedicated to VB.NET.
The name of the group is:
microsoft.public.dotnet.languages.vb
As you appear to be using the web interface to use these groups,
Find the group through this link:
http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?guid=1080912A-26C5-7040-AFDD-2224A4FEB3EA
Select English from the Tree View on the left, then scroll down to Developer
Discussions. In Developer Discussions, select Visual Tools and Languages. In
Visual Tools and Languages, select Visual Basic. In Visual Basic, select
VB.NET General Discussions.
date: Sun, 10 Feb 2008 08:09:46 -0600
author: PvdG42
|
|