how to create custom events for user control

how to create custom events for user control

Page 1 of 1

3 Replies - 34054 Views - Last Post: 15 October 2009 - 06:07 AM Rate Topic: -----

#1 abhij1987  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 32
  • Joined: 04-May 09

how to create custom events for user control

Post icon  Posted 15 October 2009 - 04:56 AM

hi Friends
Can anybody tell me how to create custom events for contol.
i have created a user control mytextbox & i am showing some properties of textbox & now i want to expose user control events Please Tell me
thanks in advance
I am showing Following properties to user
	Public Property ucText() As String
		Get
			ucText = TextBox1.Text
		End Get
		Set(ByVal Value As String)
			TextBox1.Text = Value
		End Set
	End Property
	Public Property ucForeColor() As Color
		Get
			ucForeColor = TextBox1.ForeColor
		End Get
		Set(ByVal Value As Color)
			TextBox1.ForeColor = Value
		End Set
	End Property



please tell me how to expose Events

Is This A Good Question/Topic? 0
  • +

Replies To: how to create custom events for user control

#2 dzone41  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 216
  • Joined: 21-August 09

Re: how to create custom events for user control

Posted 15 October 2009 - 05:52 AM

http://www.mobzystem...ple-events.aspx

A custom control made of other controls will use the events of the composing controls to create and call custom events.

The example in the link above could just as easily have come from the onclick event of the textbox control
Was This Post Helpful? 0
  • +
  • -

#3 dzone41  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 216
  • Joined: 21-August 09

Re: how to create custom events for user control

Posted 15 October 2009 - 06:06 AM


Public Event tbClick() As Event Handler

Private Sub textbox1_onclick(ByVal sender as object, ByVal e As _
	System.EventArgs) Handles TextBox1.onclick

	RaiseEvent tbClick(sender, e)

End Sub




In the parent class or the class that containes the control such as a form, you would add on form load (or if the control was programaticaly added, in the function that adds the control):::


AddHandler tbClick AddressOf tb_onclick




You will have to create a routine called tb_onclick or whatever the AddressOf statement calls.
Was This Post Helpful? 1
  • +
  • -

#4 theunborncoder  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 13
  • View blog
  • Posts: 123
  • Joined: 15-October 09

Re: how to create custom events for user control

Posted 15 October 2009 - 06:07 AM

hi
In your user control file write this code suppose
user control have textbox & if u want to show textbox changed event then do the following code


 Public Event TextBoxControl_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs)



  Private Sub textbox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles textbox.TextChanged
		RaiseEvent TextBoxControl_TextChanged(sender, e)

	End Sub


Was This Post Helpful? 1

Page 1 of 1