<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
  <CodeSnippet Format="1.0.0">
    <Header>
      <Title>Control Array</Title>
      <Shortcut>ControlArray</Shortcut>
    </Header>
    <Snippet>
      <Declarations>
        <Literal>
          <ID>array_name</ID>
          <ToolTip>The array's name.</ToolTip>
          <Default>m_Buttons</Default>
        </Literal>
        <Literal>
          <ID>control_type</ID>
          <ToolTip>The control type for the array.</ToolTip>
          <Default>Button</Default>
        </Literal>
        <Literal>
          <ID>event_name</ID>
          <ToolTip>The name of the event to catch for the array.</ToolTip>
          <Default>Click</Default>
        </Literal>
      </Declarations>
      <Code Language="VB">
        <![CDATA[
#Region "$control_type$ Control Array"
    ' A control array of $control_type$ objects.
    Private $array_name$() As $control_type$

    Private Sub Load_$array_name$()
        Dim num_items As Integer = 0
        For Each ctl As Control In Controls
            If TypeOf ctl Is $control_type$ Then
                num_items += 1
                ReDim Preserve $array_name$(0 To num_items - 1)
                $array_name$(num_items - 1) = DirectCast(ctl, $control_type$)
                AddHandler $array_name$(num_items - 1).$event_name$, AddressOf $array_name$_$event_name$
            End If
        Next ctl
    End Sub

    ' Handle an array member's $event_name$ event.
    Private Sub $array_name$_$event_name$(ByVal sender As System.Object, ByVal e As System.EventArgs)
        ' Tip: You can use the controls' Tag properties to store their indexes.
        Dim ctl As $control_type$ = DirectCast(sender, $control_type$)

    End Sub
#End Region '$control_type$ Control Array
]]>
      </Code>
    </Snippet>
  </CodeSnippet>
</CodeSnippets>
