Results 1 to 3 of 3

Thread: Dynamic Control Array

  1. #1

    Thread Starter
    Hyperactive Member VBD's Avatar
    Join Date
    Apr 2001
    Location
    The Place Above The Place Below Heavin
    Posts
    278

    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?
    Hello

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428

    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:
    1. Private Sub createControls()
    2.         ' You can declare this outside the sub to be able to access them directly later on
    3.         Dim myButtons(5) As Button
    4.         Dim i As Integer
    5.  
    6.         For i = 0 To myButtons.GetUpperBound(0)
    7.             myButtons(i) = New Button
    8.             ' These are not necessary
    9.             With myButtons(i)
    10.                 .Name = "foo" & i.ToString
    11.                 .Text = "&Button" & i.ToString
    12.                 ' You chose this somehow
    13.                 .Location = New Point(0, i * myButtons(i).Height)
    14.  
    15.                 ' sometimes useful when you're making too many controls
    16.                 ' You can use the Tag value later on or just leave it
    17.                 .Tag = i
    18.             End With
    19.  
    20.             AddHandler myButtons(i).Click, AddressOf myButtons_Click
    21.         Next
    22.  
    23.         ' Add the whole array to the form's controls at once. You can
    24.         ' add them one by one by calling Controls.Add() too
    25.         Me.Controls.AddRange(myButtons)
    26.     End Sub
    27.  
    28.     Private Sub myButtons_Click(ByVal sender As Object, ByVal e As EventArgs)
    29.         Dim curButton As Button = DirectCast(sender, Button)
    30.         MessageBox.Show(curButton.Name & " was clicked")
    31.     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!!

  3. #3

    Thread Starter
    Hyperactive Member VBD's Avatar
    Join Date
    Apr 2001
    Location
    The Place Above The Place Below Heavin
    Posts
    278
    Thanks, addhandler was just what I needed.
    Hello

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width