4 Replies - 8991 Views - Last Post: 16 June 2009 - 01:16 AM Rate Topic: -----

#1 mishipal  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 88
  • Joined: 04-May 09

Add Click Event to Custom Label Control

Posted 16 June 2009 - 12:02 AM

I am having problem in adding click event to my custom label control

Please help....

Public Class LgxLabel
   Public Event LtxLabClick(ByVal sender As System.Object, ByVal e As System.EventArgs)

   Private Sub LgxLabel_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Click
	  RaiseEvent LtxLabClick(sender, e)
   End Sub

   Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

   End Sub

   Private Sub Label1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label.MouseEnter
	  Label.Image = My.Resources.Btn_Back_Live_LightBlue_New
   End Sub

   Private Sub Label1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label.MouseLeave
	  Label.Image = Nothing
   End Sub

   Public Sub labtext(ByVal str As String)
	  Label.Text = str
   End Sub

   Private Sub Label_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label.Click
	  RaiseEvent LtxLabClick(sender, e)
   End Sub
End Class



Dont know where i am wrong

Is This A Good Question/Topic? 0
  • +

Replies To: Add Click Event to Custom Label Control

#2 ccubed  Icon User is offline

  • It's That Guy
  • member icon

Reputation: 162
  • View blog
  • Posts: 1,409
  • Joined: 13-June 08

Re: Add Click Event to Custom Label Control

Posted 16 June 2009 - 12:16 AM

Why do you change from ltx to lgx throughout your code?

Also, just put your code where you raise the event since an event for click already exists. You're using it when you call me.click.

Either way, what about it isn't working? Your label is clicked and the program raises the event which has no code associated with it. So it does what it should, nothing.
Was This Post Helpful? 0
  • +
  • -

#3 mishipal  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 88
  • Joined: 04-May 09

Re: Add Click Event to Custom Label Control

Posted 16 June 2009 - 12:22 AM

Sorry i am newbee....
This is my first control....

I just want to use the click event as we use in the normal label click event.
Will write the code when i use my custom control in other form.

Can you help me out
Was This Post Helpful? 0
  • +
  • -

#4 ccubed  Icon User is offline

  • It's That Guy
  • member icon

Reputation: 162
  • View blog
  • Posts: 1,409
  • Joined: 13-June 08

Re: Add Click Event to Custom Label Control

Posted 16 June 2009 - 12:35 AM

Essentially, all controls have a click event. So you really don't have to reinvent that, just make sure your custom control handles it when it is called. Your code now is fine, you just need to add code for the event. For example, add a simple msgbox statement and that messagebox will pop up after you click the label.
Was This Post Helpful? 1
  • +
  • -

#5 mishipal  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 88
  • Joined: 04-May 09

Re: Add Click Event to Custom Label Control

Posted 16 June 2009 - 01:16 AM

ok i figured it out the click event was of label placed on the base...

So this is my final code with also text property...

Finally i have my custom label....thanx to ccubed and others

Imports System.ComponentModel
Public Class LgxLabel

   Private Sub UserControl1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
	  Label.Text = ""
   End Sub

   Private Sub Label_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label.Click
	  MyBase.onclick(e)
   End Sub

   Private Sub Label1_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label.MouseEnter
	  Label.Image = My.Resources.Btn_Back_Live_LightBlue_New
   End Sub

   Private Sub Label1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Label.MouseLeave
	  Label.Image = Nothing
   End Sub

   Private Txt As String
   <Browsable(True), DefaultValue("LtxLabel")> _
	Overrides Property Text() As String
	  Get
		 Return Label.Text
	  End Get
	  Set(ByVal value As String)
		 Label.Text = value
		 Me.Invalidate()
	  End Set
   End Property
End Class


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1