Results 1 to 3 of 3

Thread: [RESOLVED] [02/03] Can have the cilick event after creating the button during runtime.

  1. #1

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Resolved [RESOLVED] [02/03] Can have the cilick event after creating the button during runtime.

    Hi All,

    I can create a Button during runtime, but the click event doesn't execute.
    Here's the code;

    VB Code:
    1. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    2.         Dim button As New Button
    3.         With button
    4.             .BackColor = Color.ForestGreen
    5.             .Height = 25
    6.             .Width = 75
    7.             .Location = New Point(10, 10)
    8.             .Text = "Hello"
    9.             AddHandler button.Click, AddressOf button_Click
    10.  
    11.         End With
    12.         Controls.Add(button)
    13.     End Sub

    This line gives me an error, button_click is not declared
    AddHandler button.Click, AddressOf button_Click

    How can I make, after creating a button during runtime, that it will execute
    after clicking the button.

    Thanks in advance,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [02/03] Can have the cilick event after creating the button during runtime.

    You need to write the button_Click sub. And this sub must has the signature of a button click. Something like this:
    VB Code:
    1. Public Sub button_Click(ByVal sender As System.Object, _
    2.                                  ByVal e As System.EventArgs)
    3.         'Do whatever you want in here for button click event
    4.         MessageBox.Show("The button was clicked.")
    5.     End Sub

  3. #3

    Thread Starter
    PowerPoster sparrow1's Avatar
    Join Date
    May 2005
    Location
    Globetrotter
    Posts
    2,820

    Re: [02/03] Can have the cilick event after creating the button during runtime.

    Hi stanav,

    That did it, thanks

    Wkr,

    sparrow1
    Wkr,
    sparrow1

    If I helped you, don't forget to Rate my post. Thank you

    I'm using Visual Studio.Net 2003 and
    2005
    How to learn VB.Net Create setup with VB 2005 Drawing for beginners VB.Net Tutorials GDI+ Tutorials
    Video's for beginners

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