How to tell if an event is being consumed?

  • Thread starter Thread starter Simon Verona
  • Start date Start date
S

Simon Verona

I have an inherited datagrid which has a "double-click" even which returns
the row that has been clicked on - this can be consumed by the form (etc)
that hosts the control to open another window that shows more detailed
information on that line.

I want to be able to change the mouse pointer when the user hovers over the
control, to make it clearer that the rows can be clicked on.... However, I
only want to change the pointer if I know that the host form is actually
picking up the double-click event.

So, the question is - how can I tell if a form has a handler for a
particular event on a control from within the control itself???

Many thanks in advance
Simon
 
Simon Verona said:
So, the question is - how can I tell if a form has a handler for a
particular event on a control from within the control itself???

Find where that event is inherited from, and see if your desired target
also inherits from that same class?

For more info see Control.DoubleClick in VS help....

LFS
 
Larry,

I'm not sure I understand you....

or perhaps I've not made myself clear...

just to make sure I'll explain my problem in a different way..

I have a usercontrol that raises an event under certain circumstances..

I'd like the usercontrol to be aware if the form that hosts the control has
any code responding to the event when it is raised....

Does this help?

Regards
Simon
 
You can check if the event is nothing...


Public Event SomeEvent(ByVal sender As Object, ByVal e As EventArgs)

....

If Me.SomeEvent Is Nothing Then
.. I'm being consumed ..
Else
.. Not Consumed ..
End If


HTH,

Sam
 
Samuel R. Neff said:
You can check if the event is nothing...


Public Event SomeEvent(ByVal sender As Object, ByVal e As EventArgs)

...

If Me.SomeEvent Is Nothing Then
.. I'm being consumed ..
Else
.. Not Consumed ..
End If


HTH,

Sam
Ok, I tried this...

In my control (which is inherited from a third party datagrid), I have an
event created with the following signature:

Public Event RowSelected(ByVal RowNo As Int32)

I'm trying to create the following code within the MouseEnter event within
the control so that if the form handles the RowSelected event the mouse
pointer changes to a hand as it moves into the control:



Private Sub DmsReport_MouseEnter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.MouseEnter

If Me.RowSelected Is Nothing Then

Cursor.Current = Cursors.Hand

End If

End Sub



This won't compile as it says that "rowselected is an event and cannot be
called directly, use raiseevent"...

I think I have misunderstood the solution!

Regards

Simon
 
Sorry, I mistyped the example. "Event" was not supposed to be part of
the event name, but is supposed to be part of the event inspection
call.

Use this:


Public Event RowSelected(ByVal RowNo As Int32)

Private Sub DmsReport_MouseEnter(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.MouseEnter

If Me.RowSelectedEvent Is Nothing Then

Cursor.Current = Cursors.Hand

End If


One thing to note is that even if the event is declared as public, the
"Event" property which you can use to inspect the event is always
private.

HTH,

Sam
 

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

Back
Top