Results 1 to 3 of 3

Thread: Change event of button created through code

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    Change event of button created through code

    Hello, I have this code to create a new button
    Code:
     Dim NewButton As New Button
    frmDownload.Controls.Add(NewButton )
    This works.
    But I want to change what happens upon clicking NewButton.
    It should start an application.
    I tried NewButton.Click but that event doesn't exist.

    Help?

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Change event of button created through code

    Code:
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            Dim foo As New Button
            AddHandler foo.Click, AddressOf FooClick
            foo.Text = "bar"
            Me.Controls.Add(foo)
        End Sub
        Private Sub FooClick(ByVal sender As System.Object, _
                                  ByVal e As System.EventArgs)
            Stop
        End Sub
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    May 2009
    Posts
    203

    Re: Change event of button created through code

    Thanks for the help,
    but I forgot to mention something.

    I'm working with different new labels created through codes aswell.

    So, just to make it simple, I want to get the button to be linked to the new label.

    Like this:

    Code:
    Dim Newlabel As New Label
    Dim NewButton As New Button
     frmDownload.Controls.Add(Newlabel )
     frmDownload.Controls.Add(NewButton )
    The new button should then be linked to that new label, so when it's clicked on it'll show the text of the label.

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