What is the IDE telling you? If I mock up your situation the error message
the IDE provides is "Handles clause requires a WithEvents variable." Which
means you need to declare your button Public WithEvents btnTest as Button.

 

  _____  

From: [email protected] [mailto:[EMAIL PROTECTED] On Behalf Of
alternate_dph
Sent: Wednesday, October 05, 2005 12:13 AM
To: [email protected]
Subject: [vbhelp] Re: Help assigning events to programmatically created
controls in vb.net

 

--- In [email protected], "Don Roberts" <[EMAIL PROTECTED]> wrote:
> Take a look at the Handles keyword.

The swiggly line is appearing right after the handles keyword.

Here's how I'm declaring it.

right inside my "Public Class frmMain", I have this line: "Public
btnTest As Button".  I have this subroutine to assign the properties
(I'm building a test application to programmatically put different
controls on a form so I know what I'm doing before I use them in the
final program):

Public Sub CreateNewButton()
        btnTest = New Button
        btnTest.Left = txtTest.Left
        btnTest.Top = txtTest.Top + txtTest.Height + 5
        btnTest.Width = lblTest.Width + 20
        btnTest.Height = txtTest.Height
        btnTest.BackColor = System.Drawing.Color.CadetBlue
        btnTest.Text = "This button can spy on you now."
        btnTest.TabIndex = 2
End Sub

in my form's load event, I have the following two lines of code (among
others):

Me.CreateNewButton()
Me.Controls.Add(btnTest)

Below my form's load event, I have this code:

Private Sub btnTest_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnTest.Click
        Me.BackColor = System.Drawing.Color.Wheat
    End Sub

[Yea, I know that's something stupid to do, but I was looking for an
easy way to know if the click event was working]
The swiggly line keeps showing up on the "btnTest" right after the
word "Handles".  Any ideas?











[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Fair play? Video games influencing politics. Click and talk back!
http://us.click.yahoo.com/T8sf5C/tzNLAA/TtwFAA/k7folB/TM
--------------------------------------------------------------------~-> 


'// =======================================================
    Rules : http://ReliableAnswers.com/List/Rules.asp
    Home  : http://groups.yahoo.com/group/vbHelp/
    =======================================================
    Post  : [email protected]
    Join  : [EMAIL PROTECTED]
    Leave : [EMAIL PROTECTED]
'// =======================================================
 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/vbhelp/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to