 |
|
 |
The code detects groupboxes but not the controls contained within them. If it does not find any controls that meet the criteria it generates an unhandled error.
|
|
|
|
 |
|
 |
It's great to cut down codes by using Array to access your Controls
|
|
|
|
 |
|
 |
Excellent work i was seeking for this kind of code from last 1 month. I searched almost all the websites i can but havn't found any such. Now i am using this to take text from multiple textbox in my project and store it into the database with the help a single line. thank you Mr.
|
|
|
|
 |
|
 |
But, I'm gradually learning to live without them. I realize this article is dated, but I just wanted to say that, after learning some C# and playing with .NET in general, I realized that control arrays are something that can be implemented in a number of ways with any .NET language I've seen. It's a little cumbersome at times, but you can actually write little wrapper classes to make things seem more transparent. Sure, it's not the best approach all of the time, but it works if you need it. I also don't mind tying multiple controls to one event, as long as I can distinguish between them in code. Fact is, with OOP like it is today, I can't imagine that the VB.NET team at Microsoft will ever bother with another control array implementation like VB6 has, I guess it's possible though. After the revisions so far and all the work they have put into getting us OO, if they had any plans to implement the feature, don't you think they would have by now? I do!
Gary W. Morris, Entepreneur
|
|
|
|
 |
|
 |
This works nice with buttons, but cant get it to work with ovalshapes from microsofts power pack. Can anyone help
|
|
|
|
 |
|
 |
Found this and wasn't sure why it was unused.
"Dim ctrls() As System.Windows.Forms.Control"
I deleted both of them and it didn't seem to effect the program.
Also if you are trying to use this in VS2005 with Option Strict and Explicit On (maybe needs it even if you don't have it on) you have to specify the imports
Imports System
Imports System.Collections
Imports System.Windows.Forms
Imports Microsoft.VisualBasic.Conversion ' Or the Val doesn't work. Headache to figure out why too!
Also in the use of it Ctype is required.
Dim textBoxes As TextBox() = CType(ControlArrayUtils.getControlArray(Me, "TextBox"), TextBox())
Took me awhile to realize it needed () after it was cast as a textbox.
|
|
|
|
 |
|
 |
I have updated the sample application to support recursive search of all controls on the forms.
The older version would only look for controls directly on the form, it would not see controls that are on a panel, groupbox, or other controls. This version will find all the controls, regardless of their parent control.
-- modified at 18:41 Monday 21st May, 2007
|
|
|
|
 |
|
 |
Excellent post.Congratulations. Microsoft should contract you before releasing vb.net without control arrays.Thanks for this wonderful contribution.
PF
|
|
|
|
 |
|
 |
Dear kepler77:
I have been using other aproaches to resolve the lack of Control Arrays in VB.NET. Yours is the better one I found for the second of the following Control Arrays issues:
1. Reusing events.
2. Accessing properties through a simple "control_name(index)" naming convention.
There is a third issue that remains to be solved and I sincerely hope that Lie1296 is right when he says that future versions of VB.NET will have Control Arrays included:
3. Not having to worry about this, since Control Arrays in VB should be taken for granted.
|
|
|
|
 |
|
 |
I agree with that, let's hope they bring it back down the road. It was a great feature of VB
|
|
|
|
 |
|
 |
Get over it my friend, the VB6 days are well over.
If there's no control array in .NET, it's just because there are better ways to do things now.
|
|
|
|
 |
|
 |
i agree, control arrays were just a way of getting around obvious deficiencies in vb6 - that you couldn't reuse event handlers, and that dynamic control creation was... difficult. Also the "too many controls on this form" thing, which you could get round by using control arrays. There are better ways to do things in vb.net, and its probably pointless trying to recreate this vb6 "feature"
|
|
|
|
 |
|
 |
OK, I should tell you that Control Array in VB6 is one of the greatest strength in VB. And obviously enough, it is NOT a way to get round VB6 "deficiencies" as you say it. Of course you can reuse event handlers in VB.NET, but what for?
Other than what have been mentioned, we use Control Arrays for ORGANIZING PURPOSE, to group multiple related controls, easily, and control arrays helps us to make sure we don't reserve too many control names. (see:
And for article creator, you might want to see MS's implementation of rec
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dv_vstechart/html/vbtchcreatingcontrolarraysinvisualbasicnetvisualcnet.asp for MS's official substitute of Control Array in VB.NET and C#)
If you reuse events in VB.NET, you're not grouping the control. And dynamic control creation wasn't difficult in VB6, it's almost as easy to dynamically create control in VB6 as it is on VB.NET.
And FYI, there are indications that future VB.NET might have Control Arrays back. This is the indication that Control Array was and is still a good idea.
|
|
|
|
 |
|
 |
"And FYI, there are indications that future VB.NET might have Control Arrays back. This is the indication that Control Array was and is still a good idea."
1. create an array of type 'control'
2. create the buttons (or wheteren controlytype) in the code
3. assign the events
4. add the newly created control to the array
Control arrays were a "solution" for one of the many limitations of VB. The thing is VB 'programmers' got used to this "solution" and can't let go of it, but please let go of it. There are more generic solutions now. Use those.
|
|
|
|
 |
|
 |
So, can this be done without using the vb6."controls arrays" object?
IE:
Me.cmd = New Microsoft.VisualBasic.Compatibility.VB6.ButtonArray(Me.components)
Me.label = New Microsoft.VisualBasic.Compatibility.VB6.LabelArray(Me.components)
For in .NET, we want to stay away from VB6 loadings. I am not sure how you create an array of commands in .NET and simply show them on the screen? This does not work...
Dim i As Int16
Dim aButton(10) As Button
For i = 0 To 9
aButton(i) = New Button
aButton(i).Left = 0
aButton(i).Height = 50
aButton(i).Width = 50
aButton(i).Top = aButton(i).Height * i + 50
aButton(i).Visible = True
aButton(i).Text = "hello " & i
Next
HAK
|
|
|
|
 |
|
 |
Yes, it can be done. I made an example where 10 buttons are created dynamicly and, when any of them are clicked the text will shown on it and buttons next to it. Dim buttons As New List(Of Button) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim i As Byte Dim aButton As Button For i = 0 To 9 aButton = New Button With aButton .Parent = Me .Left = 0 .Height = 50 .Width = 50 .Top = .Height * i + 50 .Visible = True .Tag = i .Name = "button_" & i AddHandler .Click, AddressOf button_Click End With buttons.Add(aButton) Next End Sub Private Sub button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) 'clear previous results buttons.ForEach(New Action(Of Button)(AddressOf clear_text)) 'add results Dim arv As Byte = CByte(sender.tag) sender.text = CStr(arv) If arv > 0 Then buttons(arv - 1).Text = "next >" If arv < buttons.Count - 1 Then buttons(arv + 1).Text = "< pre" End Sub Sub clear_text(ByVal element As Button) element.Text = "" End Sub
|
|
|
|
 |
|
 |
Control arrays might be a solution for limitations vb have had in the past, but the important thing is, the concept of simple managment of multiple identical controls as an array is a good idea. We doesn't really need to care how control array was or is implemented, as long as it works in such a way that allows us to manage multiple controls as an array easily without hassle.
|
|
|
|
 |
|
 |
Yeah the guy who said that is out there.
I have a form that has like a zillion control arrays on it which go to make up a highly functional interface.
I don't know how I will ever convert it.
A lot of people don't know that there was a limit on the count of controls you could have on a VB6 form and using control arrays allowed you to 'get around' that limitation. In fact, as I was finishing up that form ...
I kept hitting that limit and so I would go back and try and find some other 'set' of controls I could turn into an array.
The form was to an extent overkill and eventually it was split into about four forms but the main form still would have hit the control count limit without control arrays.
Any young gurus out there know if there is a limit on count of controls in VB.Net Windows Forms programming?
|
|
|
|
 |
|
 |
My dear friend, the fact that you don't need Control Arrays does't mean that nobody else has a good use for them.
In the type of applications I use to develop I find Control Arrays very useful since they allow me to achieve two main objectives:
1. Develop in a RAD way.
2. Use "smart" code in very few lines to perform repetitive tasks.
And you say that there are better ways to do things now... well may be there are other ways. IMHO, which one is better depends on who is the developer and what kind of application he is developing.
|
|
|
|
 |
|
 |
Carl:
OK, lets put the rubber to the road. If there is a more eloquent, ease of implementing, straight forward, non-confusing, simplistic way of implementing array controls in VB.NET -- show me.
Thanks,
HAK
|
|
|
|
 |
|
 |
It is a rhetorical request(with answer - no?). You want a better way to do -
Object(Index).parameter=value, where Object(Index) is what get's the individual object?
My way, would be to ignore the word "simplistic" and say "Yes, there is". Rather then using array(sequential blocks of memory, where block size is been set by the type, and index sets directly with what block of memory we want to handle) use list(blocks of memory, where block size is been set by the type, and index sets indirectly with what block of memory we want to handle).
Lists are declared like:
Dim a As List(Of Button)
Note that elements can have names of "whatever" and you can add and eliminate controls without having to deal all other controls in list. One can still use
Object(Index).parameter=value, just access to the block of memory is different.
I allso like to note that vb.net supports Delegate(sender,expression) where sender is what get's the individual object. So I think, this enables to depreciate need of arrays or lists in many cases(and it is simplistic).
I hope you got your wanted answer,
Margus
|
|
|
|
 |