Control Arrays in Custom Controls 
Author Message
 Control Arrays in Custom Controls

I have a VB6 custom control I'm trying to re-implement in VB.Net.  The
overall control acts as a keypad for use on a Touch Screen system.  Each
"key" on the keypad is a button control, loaded as an array.  This way,
trapping events is all done in one place - as is setting captions, fonts
colors etc.  It also helps when I add another row or column of buttons - I
can dynamically load / unload them as required.

First Problem: VB.Net does not want to automatically upgrade my Control
Project.  I guess I can live with that although its a bit {*filter*}.
Second Problem: I can't see a way to create an array of buttons in VB.Net.
At this point I assume I'm missing something as I would think creating an
array of controls would be a common requirement for many VB developers.  Any
ideas what I might be doing wrong?

Ian Mooney



Mon, 15 Mar 2004 14:50:39 GMT  
 Control Arrays in Custom Controls


Quote:
> I can't see a way to create an array of buttons in VB.Net.

Here's a small snippet:

Dim m_items As New ArrayList()

Sub AddButton()
    Dim but As New Button()

    but.Size = New Size(100, 20)
    but.Location = New Point(0, 20 * m_items.count)
    but.Text = "Button " & m_items.Count
    Me.Controls.Add(but)
    m_items.Add(but)
    AddHandler but.Click, AddressOf ButtonArrayClick
End Sub

Sub ButtonArrayClick(ByVal sender As Object, ByVal e As EventArgs)
    Dim i As Integer
    i = m_items.IndexOf(sender)
    msgbox("You clicked on Button " & i)
End Sub

--
Patrick Steele



Tue, 16 Mar 2004 11:10:47 GMT  
 Control Arrays in Custom Controls
Ian,

The thing about control arrays is that we used them for a lot of reasons.
Therefore when we look at replacements the right answer depends on the
situation.

For something like what you are describing (Patrick assumed you wanted to
add the buttons at runtime, I assume you want to add them at design time), I
think the answer is as simple as (this is not on my .NET box, so not
tested).

    Private Sub Buttons_Click(o as sender, e as buttonclickeventargs) _
                Handles Button1.CLick, Button2.Click, Button3.Click

etc.

--
Kathleen
(MS-MVP)
Reply in the newsgroup so everyone can benefit
--



Tue, 16 Mar 2004 11:51:36 GMT  
 Control Arrays in Custom Controls
Thank you (again) Your suggestion does exactly what I need.

Regards
Ian


Quote:


> > I can't see a way to create an array of buttons in VB.Net.

> Here's a small snippet:

> Dim m_items As New ArrayList()

> Sub AddButton()
>     Dim but As New Button()

>     but.Size = New Size(100, 20)
>     but.Location = New Point(0, 20 * m_items.count)
>     but.Text = "Button " & m_items.Count
>     Me.Controls.Add(but)
>     m_items.Add(but)
>     AddHandler but.Click, AddressOf ButtonArrayClick
> End Sub

> Sub ButtonArrayClick(ByVal sender As Object, ByVal e As EventArgs)
>     Dim i As Integer
>     i = m_items.IndexOf(sender)
>     msgbox("You clicked on Button " & i)
> End Sub

> --
> Patrick Steele



Tue, 16 Mar 2004 12:40:10 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. DLLs & Control Arrays + Arrays of Controls

2. custom events for control arrays

3. Array of custom controls

4. Array Problem with Custom Control

5. HELP: Custom control array and Events???

6. control arrays and custom events

7. Array Problem with Custom Control

8. Controlling Text Control Properties without a Control Array.

9. Accessing control array controls using the controls collection

10. user controls and custom controls

11. Custom Controls and Constituant Controls

12. Cannot shift focus from custom control to other control

 

 
Powered by phpBB® Forum Software