|
-
Feb 25th, 2004, 03:58 PM
#1
Thread Starter
Hyperactive Member
Dynamic Control Array
To make a long story short, I'm trying to create a scripting language for the .NET Compact Framework. I want the script to be able to generate buttons on the fly. In VB6, I would have used a control array. Now, I can't. I've done some searching and figured out how to generate controls at runtime which don't have events, and how to hard code several controls to one event. How do I create something like a control array so I can create controls at runtime and use them with an event?
-
Feb 25th, 2004, 07:52 PM
#2
Re: Dynamic Control Array
Originally posted by VBD
To make a long story short, I'm trying to create a scripting language for the .NET Compact Framework. I want the script to be able to generate buttons on the fly. In VB6, I would have used a control array. Now, I can't. I've done some searching and figured out how to generate controls at runtime which don't have events, and how to hard code several controls to one event. How do I create something like a control array so I can create controls at runtime and use them with an event?
hmm I'm not sure if I got your question right, but anyways
VB Code:
Private Sub createControls()
' You can declare this outside the sub to be able to access them directly later on
Dim myButtons(5) As Button
Dim i As Integer
For i = 0 To myButtons.GetUpperBound(0)
myButtons(i) = New Button
' These are not necessary
With myButtons(i)
.Name = "foo" & i.ToString
.Text = "&Button" & i.ToString
' You chose this somehow
.Location = New Point(0, i * myButtons(i).Height)
' sometimes useful when you're making too many controls
' You can use the Tag value later on or just leave it
.Tag = i
End With
AddHandler myButtons(i).Click, AddressOf myButtons_Click
Next
' Add the whole array to the form's controls at once. You can
' add them one by one by calling Controls.Add() too
Me.Controls.AddRange(myButtons)
End Sub
Private Sub myButtons_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim curButton As Button = DirectCast(sender, Button)
MessageBox.Show(curButton.Name & " was clicked")
End Sub
hth
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!!
-
Feb 25th, 2004, 09:03 PM
#3
Thread Starter
Hyperactive Member
Thanks, addhandler was just what I needed.
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
|