|
-
Jul 14th, 2005, 01:41 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Control arrays
I am Using Vb6 for quite a few years but new to vb.net.
Vb.net does not have control arrays .
Control arrays provided :
1. adding controls to an array at runtime .
2. Removing controls From an array at runtime .
3. changing properties of the controls by looping through the array.
4. using a single procedure event for all the members of the control array.
What is the best method to implement this In vb.net
-
Jul 14th, 2005, 02:06 AM
#2
Re: Control arrays
The question of control arrays is a well worn one around here, so forum search should yield quite a few results. I did find a couple of articles on MSDN just the other day that may be of interest to you and others on the subject.
http://msdn.microsoft.com/library/de...visualcnet.asp
http://msdn.microsoft.com/library/de...trolarrays.asp
-
Jul 14th, 2005, 03:01 AM
#3
Re: Control arrays
Yeah, have a search on this site because as jmcilhinney said, it's been done to death. They were convenient but after a while you do find better ways around them. However, if you've searched and the info hasn't helped, then feel free to continue your pursuit here and I'll help you out.
I use Microsoft Visual Basic 2005. (Therefore, most code samples I provide will be based around the .NET Framework v2.0, unless otherwise specified)
-
Jul 14th, 2005, 03:13 AM
#4
Re: Control arrays
In .net you can have an array of anything you want. Fact. Controls are just classes like anything else.
-
Jul 14th, 2005, 03:31 AM
#5
Thread Starter
Fanatic Member
Re: Control arrays
Thanks jmcilhinney . I read the msdn link.
But i have a problem.
Lets say . I have a requirement where label controls need to be added at runtime and i don't know beforehand that how many will be required and
ofcourse what their name be.
If we see this code :
Private Sub AddEmailAddress()
Dim txtEmail As New TextBox
Dim lblEmail As New Label
' Set the desired properties
txtEmail.Top = txtAddress.Top + txtAddress.Height + 10
txtEmail.Left = txtAddress.Left
lblEmail.Text = "Email"
lblEmail.Location = New Point(lblAddress.Location.X, _
txtEmail.Location.Y)
' Add to the collection
tpAddress.Controls.Add(txtEmail)
tpAddress.Controls.Add(lblEmail)
AddHandler txtEmail.Enter, AddressOf ProcessEnter
End Sub
adding controls at runtime and creating their event handlers is Fine , But i don't know what purpose this code will solve.
Because If i know i have to add A textbox and A label , i would not do that at runtime .
I want to add controls at runtime and their number can depend on a variable.
How to do that ?
-
Jul 14th, 2005, 03:47 AM
#6
Re: Control arrays
Use a loop and do this the number of times that your variable prescribes. You will presumably need to have some method of setting their Location based on the value of the loop counter. You can add these controls to an array or collection, other than the form's Controls collection, as they are created if you want. You can then access them using that array or collection without having to allow for the other controls on the form.
-
Jul 14th, 2005, 05:20 AM
#7
PowerPoster
Re: Control arrays
Hi,
Control Arays have NOT dissapeared from .NET. It is the Control Index Number property which is no longer available.
The following thread in the forum code bank gives you all you are asking for.
http://www.vbforums.com/showthread.php?t=328100
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Jul 15th, 2005, 06:28 AM
#8
Thread Starter
Fanatic Member
Re: Control arrays ( Resolved )
Thanks taxes.
That was exactly what i was looking for.
-
Jul 15th, 2005, 07:36 AM
#9
PowerPoster
Re: [RESOLVED] Control arrays
Glad to have helped. Sorry I did not see your post sooner
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
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
|