User controls in VB.NET

  • Thread starter Thread starter sonali_reddy123
  • Start date Start date
S

sonali_reddy123

Hi,

I need a help regarding use of a user defined control in VB.NET.
I could able to prepare a user control and add it to my project
toolbox but the problem is how to pass the data from the application to
the events on the user control.

I found get and set methods do these two methods satisfy the entire
need or is their anything more I should know.

Sample example will be a better response.

Thanks in advance.
 
I need a help regarding use of a user defined control in VB.NET. .. . .
how to pass the data from the application to the events on the user
control.

You don't pass data /to/ events.
Use properties (Get and Set) to pass data into the UserControl,
then "handle" the events raised /by/ the UserControl back your
"main" application. Over-simplifying this:

Class MyUserControl
. . .
Public Event X_Changed()
. . .
Public Property X() as Integer
Get
Return m_iX
End Get
Set( Value as Integer )
m_iX = Value
RaiseEvent X_Changed
End Set
End Property
Private m_iX as Integer = 0
End Class

Class Form1
Friend WithEvents uc1 as MyUserControl
. . .
Private Sub Button1_Click( _
byVal sender as Object _
, ByVal e as EventArgs _
) Handles uc1.Button1_Click

uc1.X = 99

End Sub

Private Sub uc1_X_Changed( _
byVal sender as Object _
, ByVal e as EventArgs _
) Handles uc1.X_Changed
MsgBox "Something changed X"
End Sub
End Class

HTH,
Phill W.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Back
Top