How to use CancelEventArgs?

nescartel

Member
Joined
Jun 10, 2007
Messages
22
Programming Experience
3-5
i have this event that is activated by mouse click,
and on click i pass the control to another sub 'checkserialport()',
and it will check whether serial port is open or closed.
if serial port is currently closed,
i want to use e.cancel = TRUE to cancel the mouse click,
but somehow i am getting this error message:

VB.NET:
Error	1	Method 'Private Sub rbDisableGauge_Click(sender As Object, e As 
System.ComponentModel.CancelEventArgs)' cannot handle Event 'Public Event Click(sender As 
Object, e As System.EventArgs)' because they do not have the same signature.	
D:\VB\Projects\Diagnose\DiagnoseII\DiagnoseII\Form1.vb	65	66	Diagnostic

this is the click event, and error is at the "click" word, which is in bold:

VB.NET:
Private Sub rbDisableGauge_Click(ByVal sender As Object, ByVal e As _
   System.ComponentModel.CancelEventArgs) Handles rbDisableGauge.[B][COLOR="Red"]Click[/COLOR][/B]
        CheckSerialPort()
        ResetTextbox()

        TxTemp = "15 6 53 2 1 43"
        TxBuffer = TxTemp.Split(" ")

        ProcessInput(TxBuffer, TxBufferSize)
        TransmitData(TxBuffer, TxBufferSize)
        Wait(Interval)
        ShowRxData(TxBufferSize)
    End Sub

can anyone show me the correct way to do this?
any help is very much appreciated, thank you...
 
What is it you want to do?? There is no point in cancelling a control mouse click. If you mean you want to cancel a click that happened some time ago, that is pointless and not possible too. If you have asynchronous work going on (caused by a click sometime perhaps? though it does not look so from your code) that you want to cancel then you should look to use BackgroundWorker component.
 
The above I think tells you what you need to know, but incase you get the same message again, you might want to know what the error means..

The problem is in the brackets, where "e" for a mousehandler needs to be "system.windows.forms.mouseeventargs" rather than what you have which is "canceleventargs"

When possible, use the two comboboxes at the top of the code window to select an object and the event, as this will automaticaly generate the right type for "e"
 
hello again,

what i'm trying to do is,
when user clicks the button,
program will check whether serial port is open or closed.
if open, proceed with code,
but if serial port is closed,
then exit from the event without doing anything.

i could do this by using if else conditional branching,
but i think i've seen people using e.cancel statement,
so is it possible for me to use this e.cancel on mouse click?
 
The if statemnt is definately the way to go about it, I see no reason to use anything else, and im not sure how you would change the signature of the mouseclick arguments anyway. e is not 'canceleventargs' already, because as stated by (John I think) above, it is not relevant

Stick to the If statement
 
Back
Top