|
-
Aug 27th, 2003, 11:14 AM
#1
Thread Starter
PowerPoster
Why doesn't .NET support control arrays
What is it about .NET that won't let it support an array of objects?WHat is the purpose of leaving out this functionality?
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Aug 27th, 2003, 11:34 AM
#2
An array of objects?
Dim a() As Object
An array of controls?
Dim ctrl() As Textbox
'or if they exist already
Dim ctrl() As TextBox={TextBox1,TextBox2,TextBox3}
And as far as events go why not just add more controls to the same event handle. If this is something you'll need to do often then just make a macro to speed up the process.
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click, Button3.Click, Button2.Click, Button1.Click
I don't see that any functionality was lost in fact I'd say we gained some. Now you can have controls of different types act the same as a control array.
-
Aug 27th, 2003, 12:57 PM
#3
Thread Starter
PowerPoster
Yah one control can handle events from multiple controls, but how do you know which control was clicked?
With a control array you could find out by getting the index....msgbox Button(Index). But how do you do that with .Net?
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Aug 27th, 2003, 01:07 PM
#4
Generally the sender argument is the control that is raising the event.
-
Aug 27th, 2003, 01:10 PM
#5
I wonder how many charact
VB Code:
If TypeOf (sender) Is Button Then
Dim c As Button
c = sender
MsgBox(c.Name)
End If
-
Aug 27th, 2003, 01:26 PM
#6
Thread Starter
PowerPoster
thanks, that seems to work fine.
One other question, why is the name property not in the Sender list?
If you type msgbox Sender. there is only GetType there is no Name property.
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Aug 27th, 2003, 01:40 PM
#7
I wonder how many charact
Because the sender may not have a name property. I know, sounds ludicrous... but i think it has more to do with being able to have any object raise the event, and not all objects have the same properties, so you need a layer of abstraction in there.
-
Aug 27th, 2003, 01:40 PM
#8
Frenzied Member
Originally posted by Arc
thanks, that seems to work fine.
One other question, why is the name property not in the Sender list?
If you type msgbox Sender. there is only GetType there is no Name property.
Not all the objects have a name property. If you just type MessageBox.Show(Sender.Name), then if the object has a name property it should show you.
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Aug 27th, 2003, 01:43 PM
#9
Frenzied Member
Originally posted by nemaroller
Because the sender may not have a name property. I know, sounds ludicrous... but i think it has more to do with being able to have any object raise the event, and not all objects have the same properties, so you need a layer of abstraction in there.
Didn't mean to repeat you!
'Heading for the automatic overload'
Marillion, Brave, The Great Escape, 1994
'How will WE stand the FIRE TOMORROW?'
Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979
-
Aug 27th, 2003, 01:45 PM
#10
Thread Starter
PowerPoster
Makes sense I guess... but it makes it difficult to figure out on your own
-We have enough youth. How about a fountain of "Smart"?
-If you can read this, thank a teacher....and since it's in English, thank a soldier.

-
Aug 27th, 2003, 01:46 PM
#11
I wonder how many charact
Considering we both posted at the same time, it could have easily concluded with your message being posted first. But as it turns out, I won!!!!
HARARHAR!
-
Aug 27th, 2003, 02:00 PM
#12
Originally posted by nemaroller
VB Code:
If TypeOf (sender) Is Button Then
Dim c As Button
c = sender
MsgBox(c.Name)
End If
just a little comment on this: I dont think there is a need to check the type of the object (unless ofcourse the sub handles events for different types of objects). Umm also if option strict is on, c = sender wouldn't work I think it's a better coding practice to convert it even if option strict is off
I would use c=DirectCast(sender, Button)
(I think directCast works faster than Ctype )
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
-
Aug 27th, 2003, 02:06 PM
#13
I wonder how many charact
Umm also if option strict is on, c = sender wouldn't work I think it's a better coding practice to convert it even if option strict is off
Yea... well in my race against Lunatic, I skipped that part
-
Aug 27th, 2003, 02:13 PM
#14
rate my posts if they help ya!
Extract thumbnail without reading the whole image file: (C# - VB)
Apply texture to bitmaps: (C# - VB)
Extended console library: (VB)
Save JPEG with a certain quality (image compression): (C# - VB )
VB.NET to C# conversion tips!!
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
|