M
Mike
James said:A lot of discussion of this task makes it more confusing than it needs
to be.
To broadcast an event to another form (or forms) you need to create the
event in the form from which it is to be broadcast (FormA):
Public Event MonthChanged(ByVal Month As Integer)
and then raise the event whenever you need to:
Private Sub MonthCalendar1_DateChanged(ByVal sender As Object, _
ByVal e As
System.Windows.Forms.DateRangeEventArgs) _
Handles MonthCalendar1.DateChanged
RaiseEvent MonthChanged(e.start)
End Sub
On any form that needs to listen for that event, you create the event
handler:
Private Sub MonthChangeHandler(ByVal NewMonth as integer)
Textbox1=NewMonth.ToShortDateString
End Sub
and tie the event handler to the event (eg, in the form load event):
AddHandler FormA.MonthChanged, AddressOf MonthChangeHandler
James, I am currently working on class events and controls.
So far for events, the class is modeled like you described above but
the events are triggered by callbacks:
public classs CWildcatEvents
' class events
Public Event OnPageMessageHandler(ByVal msg As TPageMessage)
Public Event OnChatMessageHandler(ByVal msg As TChatMessage)
Public Event OnFileEventHandler(ByVal page As TSystemEventFileInfo)
Public Event OnMailEventHandler(ByVal page As TSystemEventMailInfo)
' Call back handler
Delegate Function cbWildcatDelegate( _
ByVal userdata As UInt32, _
ByRef msg As TChannelMessage) As UInt32
end class
If a developer may prepare it like so in his main code:
' event custom event handler
Sub OnChatMessage(ByVal page As TChatMessage)
End Sub
...
Dim evt As New CWildcatEvents
evt.RegisterChatChannel()
evt.AddChatMessageHandler(AddressOf OnChatMessage)
When the evt object is instantiated, it will prepare the delegate
callback.
The callback delegate has logic like for this event:
Dim page As TChatMessage = ChannelEventType(Of TChatMessage)(cmsg)
RaiseEvent OnChatMessageHandler(page)
My Question, I think I want to make this a standard event prototype,
with sender and EventArgs parameters, for example:
Public Event OnChatMessageHandler( _
ByVal sender As Object, ByVal e As System.EventArgs)
How do I prepare the call back to set this up? Who would be the
"sender" in this case, the class? IOW, I do I prepare the RaiseEvents?
RaiseEvent OnChatMessageHandler(Me?, page?)
Also, this may be related as I am currently trying to make this a
CONTROL (or COMPONENT?) so it can be added the the IDE toolbar and the
control be dropped on a from.
Once I figure that out, will the proper setup for this mean that I
will need to use a event handler with Sender and EventArgs?
Thanks for any insight you (or anyone else) can provide.
--