Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Custom control - on_click

Status
Not open for further replies.

nicsin

Programmer
Joined
Jul 31, 2003
Messages
743
Location
GB
Hi all,

I have created in code a visible control and i am trying to apply an on_click event to it with no success my code is

Code:
Public Sub createItem(ByVal itmName As String, ByVal itmImagePath As String, ByVal itmParent As XPExplorerBar.Expando)
        Dim itmTemp As New XPExplorerBar.TaskItem
        itmTemp.Name = itmName
        itmTemp.Text = itmName
        Dim tmpImage As System.Drawing.Image = System.Drawing.Image.FromFile(itmImagePath)
        itmTemp.Image = tmpImage
        itmParent.Items.Add(itmTemp)
End Sub

Private Sub itmTemp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles itmTemp.Click
'do something
end sub

and the error i am getting is



Handles clause requires a WithEvents variable defined in the containing type or one of its base types

Handles itmTemp.Click



Any thoughts cause i am completely stuck!

Thnx
 
You need to declare itmTemp at the class level:

Code:
Class MyClass

  Private WithEvents itmTemp as XPExplorerBar.TaskItem

  private sub New()
    itmTemp = new XPExplorerBar.TaskItem
  end sub

  Private Sub itmTemp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles itmTemp.Click
    'do something
  end sub 

end class

-Rick

VB.Net Forum forum796 forum855 ASP.NET Forum
[monkey]I believe in killer coding ninja monkeys.[monkey]
 
Or you can use the AddHandler method:
Code:
Public Sub createItem(ByVal itmName As String, ByVal itmImagePath As String, ByVal itmParent As XPExplorerBar.Expando)
        Dim itmTemp As New XPExplorerBar.TaskItem
        itmTemp.Name = itmName
        itmTemp.Text = itmName
        Dim tmpImage As System.Drawing.Image = System.Drawing.Image.FromFile(itmImagePath)
        itmTemp.Image = tmpImage
        AddHandler itmTemp.Click, AddressOf itmTemp_Click
        itmParent.Items.Add(itmTemp)
End Sub

Private Sub itmTemp_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'do something
end sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top