For some time now I have been struggling trying to understand how to handle
events originating in a User Control that I have designed when using this in
an application. Basically I need to respond to button clicks in my user
control. I have struggled trying to understand Delegates, aqnd m still
struggling. I then came across the following tutorial on MSDN and thought I
had 'cracked it'
http://msdn.microsoft.com/library/de...singevents.asp
I have used the follwoing code in my User Control to raise the event:-
Public Class ResultsControl
Inherits System.Windows.Forms.UserControl
Public Event Result(ByVal Percent As String)
Private Sub cmdPotassium_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdPotassium.Click
RaiseEvent Result(txtPotassium.Text)
End Sub
I have used the following code in my application to handle the event:-
Imports InfoResultsControl
Public Class frmOriginal
Private WithEvents mResultsPasteIt As InfoResultsControl.ResultsControl
This works:-
Private Sub mResultsPasteIt_Result(ByVal Percent As String) Handles
ResultsControl.Result
MsgBox(Percent)
End Sub
This DOES NOT work
Private Sub mResultsPasteIt_Result(ByVal Percent As String) Handles
mResultsPasteIt.Result
MsgBox(Percent)
End Sub
From the article, I should be using the second option and the WithEvents
variable, but as stated above this does not work, whereas the first option
does work. What am I doing wrong??? Am I correct in pursuing this method, or
should I work harder on understanding delegates, and if the latter is there
an easy tutorial on the Internet?? I am a hobbyist programmer.
I notice that mResultsPasteIt_Result when displayed in the L dropdown box
has a lock icon by it - is this relevant and correct?
Many thanks
Paul Bromley