Dynamic buttons

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • TyBreaker

    #1

    Dynamic buttons

    I'm creating buttons on the fly as my program runs and I'm storing them
    all in an array for future referencing. How do I assign a click event
    handler to a button I've created dynamically?
    --
    ______ ___ __
    /_ __/_ __/ _ )_______ ___ _/ /_____ ____
    / / / // / _ / __/ -_) _ `/ '_/ -_) __/
    /_/ \_, /____/_/ \__/\_,_/_/\_\\__/_/
    /___/

    There are 10 types of people in this world; those who understand the
    binary numbering system and those who don't.

    There's no place like 127.0.0.1.

    ASCII a silly question, get a silly ANSI.
  • Armin Zingler

    #2
    Re: Dynamic buttons

    "TyBreaker" <tybreakerNO@SP AMhotmail.com> schrieb[color=blue]
    > I'm creating buttons on the fly as my program runs and I'm storing
    > them all in an array for future referencing. How do I assign a
    > click event handler to a button I've created dynamically?[/color]


    http://msdn.microsoft.com/library/en...OnRemoveOn.asp



    Armin

    Comment

    • Cerebrus

      #3
      Re: Dynamic buttons

      Hi,

      Below is an example :
      ----------------------------------------------
      Private Sub AddButtons()
      Dim NewBtn As New Button()
      Me.Controls.Add (NewBtn)
      idx = Me.Controls.Ind exOf(NewBtn)
      NewBtn.Location = New System.Drawing. Point(24 * idx, 24 * idx)
      NewBtn.Text = "Button " & idx.ToString()
      ' Note the following statement :
      AddHandler NewBtn.Click, AddressOf MyButtonClickHa ndler
      End Sub

      Private Sub MyButtonClickHa ndler(ByVal sender As System.Object, ByVal e
      As System.EventArg s)
      ' Handle the Click events of all the Buttons here...
      End Sub
      ----------------------------------------------

      HTH,

      Regards,

      Cerebrus.

      Comment

      Working...