This is a multi-part message in MIME format.

------=_NextPart_000_000A_01C3A487.88D84180
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

When using an event with a delegate type of CancelEventHandler, =
shouldn't the delegate be checking to see if the Cancel property on the =
event object has been set to true and stop execution upon the first =
'cancel' it encounters? It seems you will only get the cancel =
information for the last event hanlder to process, and all previous are =
effectively ignored.

Am I missing something?

Here is a quick example to show what I mean:

public class MyForm : Form {
public event CancelEventHandler MyCancelEvent;

private void CancelHandlerOne(object sender, CancelEventArgs e) {
System.Diagnostics.Debug.WriteLine("Handler 1: Event.Cancel passed =
in is " + e.Cancel.ToString());
}


private void CancelHandlerTwo(object sender, CancelEventArgs e) {
System.Diagnostics.Debug.WriteLine("Handler 2: Event.Cancel passed =
in is " + e.Cancel.ToString());
System.Diagnostics.Debug.WriteLine("Handler 2: Setting Event.Cancel =
to " + bool.TrueString);
}

private void CancelHandlerThree(object sender, CancelEventArgs e) {
System.Diagnostics.Debug.WriteLine("Handler 3: Event.Cancel passed =
in is " + e.Cancel.ToString());
}

private void MyForm_Load(object sender, System.EventArgs e) {
MyCancelEvent +=3D new CancelEventHandler(CancelHandlerOne);
MyCancelEvent +=3D new CancelEventHandler(CancelHandlerTwo);
MyCancelEvent +=3D new CancelEventHandler(CancelHandlerThree);
}

private void button1_Click(object sender, System.EventArgs e) {
CancelEventArgs evt =3D new CancelEventArgs(false);
if (MyCancelEvent !=3D null)
MyCancelEvent(this, evt);
System.Diagnostics.Debug.WriteLine("Event.Cancel after event call is =
" + evt.Cancel.ToString());
}

Pressing the button produces the following output:

Handler 1: Event.Cancel passed in is False
Handler 2: Event.Cancel passed in is False
Handler 2: Setting Event.Cancel to True
Handler 3: Event.Cancel passed in is False
Event.Cancel after event call is False

------=_NextPart_000_000A_01C3A487.88D84180
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1264" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>When using an event with a delegate =
type of=20
CancelEventHandler, shouldn't the delegate be checking to see if the =
Cancel=20
property on the event object has been set to true and stop execution =
upon the=20
first 'cancel' it encounters?&nbsp; It seems you will only get =
the&nbsp;cancel=20
information for&nbsp;the last event hanlder to process, and all previous =
are=20
effectively ignored.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Am I missing something?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here is a quick example to show what I=20
mean:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>
<P><FONT face=3D"Courier New" size=3D2>public class MyForm : Form =
{<BR>&nbsp; public=20
event CancelEventHandler MyCancelEvent;</FONT></P>
<P><FONT face=3D"Courier New" size=3D2>&nbsp; private void =
CancelHandlerOne(object=20
sender, CancelEventArgs e) {<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT=20
face=3D"Courier New" =
size=3D2>System.Diagnostics.Debug.WriteLine("Handler 1:=20
Event.Cancel passed in is " + e.Cancel.ToString());<BR>&nbsp; =
</FONT><FONT=20
face=3D"Courier New" size=3D2>}</FONT></P>
<P><FONT face=3D"Courier New" size=3D2></FONT></P>
<P><FONT face=3D"Courier New" size=3D2>&nbsp; private void =
CancelHandlerTwo(object=20
sender, CancelEventArgs e) {<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT=20
face=3D"Courier New" =
size=3D2>System.Diagnostics.Debug.WriteLine("Handler 2:=20
Event.Cancel passed in is " + =
e.Cancel.ToString());<BR>&nbsp;&nbsp;&nbsp;=20
</FONT><FONT face=3D"Courier New"=20
size=3D2>System.Diagnostics.Debug.WriteLine("Handler 2: Setting =
Event.Cancel to "=20
+ bool.TrueString);<BR>&nbsp; </FONT><FONT face=3D"Courier New"=20
size=3D2>}</FONT></P>
<P><FONT face=3D"Courier New" size=3D2>&nbsp; private void =
CancelHandlerThree(object=20
sender, CancelEventArgs e) {<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT=20
face=3D"Courier New" =
size=3D2>System.Diagnostics.Debug.WriteLine("Handler 3:=20
Event.Cancel passed in is " + e.Cancel.ToString());<BR>&nbsp; =
</FONT><FONT=20
face=3D"Courier New" size=3D2>}</FONT></P>
<P><FONT face=3D"Courier New" size=3D2>&nbsp; private void =
MyForm_Load(object=20
sender, System.EventArgs e) {<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT=20
face=3D"Courier New" size=3D2>MyCancelEvent +=3D new=20
CancelEventHandler(CancelHandlerOne);<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT =

face=3D"Courier New" size=3D2>MyCancelEvent +=3D new=20
CancelEventHandler(CancelHandlerTwo);<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT =

face=3D"Courier New" size=3D2>MyCancelEvent +=3D new=20
CancelEventHandler(CancelHandlerThree);<BR>&nbsp; </FONT><FONT=20
face=3D"Courier New" size=3D2>}</FONT></P>
<P><FONT face=3D"Courier New" size=3D2>&nbsp; private void =
button1_Click(object=20
sender, System.EventArgs e) {<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT=20
face=3D"Courier New" size=3D2>CancelEventArgs evt =3D new=20
CancelEventArgs(false);<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT =
face=3D"Courier New"=20
size=3D2>if (MyCancelEvent !=3D null)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
</FONT><FONT=20
face=3D"Courier New" size=3D2>MyCancelEvent(this, =
evt);<BR>&nbsp;&nbsp;&nbsp;=20
</FONT><FONT face=3D"Courier New"=20
size=3D2>System.Diagnostics.Debug.WriteLine("Event.Cancel after event =
call is " +=20
evt.Cancel.ToString());<BR>&nbsp; </FONT><FONT face=3D"Courier New"=20
size=3D2>}</FONT></P>
<P><FONT face=3DArial size=3D2>Pressing the button produces the =
following=20
output:</FONT></P><FONT size=3D1>
<P><FONT face=3D"Courier New" size=3D2>Handler 1: Event.Cancel passed in =
is=20
False<BR></FONT><FONT face=3D"Courier New" size=3D2>Handler 2: =
Event.Cancel passed=20
in is False<BR></FONT><FONT face=3D"Courier New" size=3D2>Handler 2: =
Setting=20
Event.Cancel to True<BR></FONT><FONT face=3D"Courier New" =
size=3D2>Handler 3:=20
Event.Cancel passed in is False<BR></FONT><FONT face=3D"Courier New"=20
size=3D2>Event.Cancel after event call is=20
False</FONT></P></FONT></DIV></BODY></HTML>

------=_NextPart_000_000A_01C3A487.88D84180--

Re: Logic flaw in CancelEventHandler? by Michael

Michael
Thu Nov 06 23:33:44 CST 2003

This is a multi-part message in MIME format.

------=_NextPart_000_01C0_01C3A4BE.6B22A540
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Where's the e.Cancel =3D true;?

-mike
MVP

"Tom Briese" <tbriese@artemisalliance.com> wrote in message =
news:%23DGtIoLpDHA.2772@TK2MSFTNGP10.phx.gbl...
When using an event with a delegate type of CancelEventHandler, =
shouldn't the delegate be checking to see if the Cancel property on the =
event object has been set to true and stop execution upon the first =
'cancel' it encounters? It seems you will only get the cancel =
information for the last event hanlder to process, and all previous are =
effectively ignored.

Am I missing something?

Here is a quick example to show what I mean:

public class MyForm : Form {
public event CancelEventHandler MyCancelEvent;

private void CancelHandlerOne(object sender, CancelEventArgs e) {
System.Diagnostics.Debug.WriteLine("Handler 1: Event.Cancel passed =
in is " + e.Cancel.ToString());
}


private void CancelHandlerTwo(object sender, CancelEventArgs e) {
System.Diagnostics.Debug.WriteLine("Handler 2: Event.Cancel passed =
in is " + e.Cancel.ToString());
System.Diagnostics.Debug.WriteLine("Handler 2: Setting =
Event.Cancel to " + bool.TrueString);
}

private void CancelHandlerThree(object sender, CancelEventArgs e) {
System.Diagnostics.Debug.WriteLine("Handler 3: Event.Cancel passed =
in is " + e.Cancel.ToString());
}

private void MyForm_Load(object sender, System.EventArgs e) {
MyCancelEvent +=3D new CancelEventHandler(CancelHandlerOne);
MyCancelEvent +=3D new CancelEventHandler(CancelHandlerTwo);
MyCancelEvent +=3D new CancelEventHandler(CancelHandlerThree);
}

private void button1_Click(object sender, System.EventArgs e) {
CancelEventArgs evt =3D new CancelEventArgs(false);
if (MyCancelEvent !=3D null)
MyCancelEvent(this, evt);
System.Diagnostics.Debug.WriteLine("Event.Cancel after event call =
is " + evt.Cancel.ToString());
}

Pressing the button produces the following output:

Handler 1: Event.Cancel passed in is False
Handler 2: Event.Cancel passed in is False
Handler 2: Setting Event.Cancel to True
Handler 3: Event.Cancel passed in is False
Event.Cancel after event call is False

------=_NextPart_000_01C0_01C3A4BE.6B22A540
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1264" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Where's the e.Cancel =3D =
true;?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>-mike</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>MVP</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>"Tom Briese" &lt;<A=20
href=3D"mailto:tbriese@artemisalliance.com">tbriese@artemisalliance.com</=
A>&gt;=20
wrote in message <A=20
href=3D"news:%23DGtIoLpDHA.2772@TK2MSFTNGP10.phx.gbl">news:%23DGtIoLpDHA.=
2772@TK2MSFTNGP10.phx.gbl</A>...</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV><FONT face=3DArial size=3D2>When using an event with a delegate =
type of=20
CancelEventHandler, shouldn't the delegate be checking to see if the =
Cancel=20
property on the event object has been set to true and stop execution =
upon the=20
first 'cancel' it encounters?&nbsp; It seems you will only get =
the&nbsp;cancel=20
information for&nbsp;the last event hanlder to process, and all =
previous are=20
effectively ignored.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Am I missing something?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here is a quick example to show what =
I=20
mean:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>
<P><FONT face=3D"Courier New" size=3D2>public class MyForm : Form =
{<BR>&nbsp;=20
public event CancelEventHandler MyCancelEvent;</FONT></P>
<P><FONT face=3D"Courier New" size=3D2>&nbsp; private void =
CancelHandlerOne(object=20
sender, CancelEventArgs e) {<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT=20
face=3D"Courier New" =
size=3D2>System.Diagnostics.Debug.WriteLine("Handler 1:=20
Event.Cancel passed in is " + e.Cancel.ToString());<BR>&nbsp; =
</FONT><FONT=20
face=3D"Courier New" size=3D2>}</FONT></P>
<P><FONT face=3D"Courier New" size=3D2></FONT></P>
<P><FONT face=3D"Courier New" size=3D2>&nbsp; private void =
CancelHandlerTwo(object=20
sender, CancelEventArgs e) {<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT=20
face=3D"Courier New" =
size=3D2>System.Diagnostics.Debug.WriteLine("Handler 2:=20
Event.Cancel passed in is " + =
e.Cancel.ToString());<BR>&nbsp;&nbsp;&nbsp;=20
</FONT><FONT face=3D"Courier New"=20
size=3D2>System.Diagnostics.Debug.WriteLine("Handler 2: Setting =
Event.Cancel to=20
" + bool.TrueString);<BR>&nbsp; </FONT><FONT face=3D"Courier New"=20
size=3D2>}</FONT></P>
<P><FONT face=3D"Courier New" size=3D2>&nbsp; private void=20
CancelHandlerThree(object sender, CancelEventArgs e) =
{<BR>&nbsp;&nbsp;&nbsp;=20
</FONT><FONT face=3D"Courier New"=20
size=3D2>System.Diagnostics.Debug.WriteLine("Handler 3: Event.Cancel =
passed in=20
is " + e.Cancel.ToString());<BR>&nbsp; </FONT><FONT face=3D"Courier =
New"=20
size=3D2>}</FONT></P>
<P><FONT face=3D"Courier New" size=3D2>&nbsp; private void =
MyForm_Load(object=20
sender, System.EventArgs e) {<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT=20
face=3D"Courier New" size=3D2>MyCancelEvent +=3D new=20
CancelEventHandler(CancelHandlerOne);<BR>&nbsp;&nbsp;&nbsp; =
</FONT><FONT=20
face=3D"Courier New" size=3D2>MyCancelEvent +=3D new=20
CancelEventHandler(CancelHandlerTwo);<BR>&nbsp;&nbsp;&nbsp; =
</FONT><FONT=20
face=3D"Courier New" size=3D2>MyCancelEvent +=3D new=20
CancelEventHandler(CancelHandlerThree);<BR>&nbsp; </FONT><FONT=20
face=3D"Courier New" size=3D2>}</FONT></P>
<P><FONT face=3D"Courier New" size=3D2>&nbsp; private void =
button1_Click(object=20
sender, System.EventArgs e) {<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT=20
face=3D"Courier New" size=3D2>CancelEventArgs evt =3D new=20
CancelEventArgs(false);<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT =
face=3D"Courier New"=20
size=3D2>if (MyCancelEvent !=3D =
null)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
</FONT><FONT face=3D"Courier New" size=3D2>MyCancelEvent(this,=20
evt);<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT face=3D"Courier New"=20
size=3D2>System.Diagnostics.Debug.WriteLine("Event.Cancel after event =
call is "=20
+ evt.Cancel.ToString());<BR>&nbsp; </FONT><FONT face=3D"Courier New"=20
size=3D2>}</FONT></P>
<P><FONT face=3DArial size=3D2>Pressing the button produces the =
following=20
output:</FONT></P><FONT size=3D1>
<P><FONT face=3D"Courier New" size=3D2>Handler 1: Event.Cancel passed =
in is=20
False<BR></FONT><FONT face=3D"Courier New" size=3D2>Handler 2: =
Event.Cancel passed=20
in is False<BR></FONT><FONT face=3D"Courier New" size=3D2>Handler 2: =
Setting=20
Event.Cancel to True<BR></FONT><FONT face=3D"Courier New" =
size=3D2>Handler 3:=20
Event.Cancel passed in is False<BR></FONT><FONT face=3D"Courier New"=20
size=3D2>Event.Cancel after event call is=20
False</FONT></P></FONT></DIV></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_01C0_01C3A4BE.6B22A540--


Re: Logic flaw in CancelEventHandler? by Tom

Tom
Fri Nov 07 09:46:50 CST 2003

This is a multi-part message in MIME format.

------=_NextPart_000_0009_01C3A514.155E33D0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Sorry, yes I failed to include the setting of the value. The event =
handlers should look like:

private void CancelHandlerTwo(object sender, CancelEventArgs e) {
System.Diagnostics.Debug.WriteLine("Handler 2: Event.Cancel passed =
in is " + e.Cancel.ToString());
System.Diagnostics.Debug.WriteLine("Handler 2: Setting =
Event.Cancel to " + bool.TrueString);
e.Cancel =3D true;
}

private void CancelHandlerThree(object sender, CancelEventArgs e) {
System.Diagnostics.Debug.WriteLine("Handler 3: Event.Cancel passed =
in is " + e.Cancel.ToString());
System.Diagnostics.Debug.WriteLine("Handler 3: Setting =
Event.Cancel to " + bool.FalseString);
e.Cancel =3D false;
}

And the output would then be:

Handler 1: Event.Cancel passed in is False
Handler 2: Event.Cancel passed in is False
Handler 2: Setting Event.Cancel to True
Handler 3: Event.Cancel passed in is True
Handler 3: Setting Event.Cancel to False
Event.Cancel after event call is False

I guess each handler could take responsibility for inspecting the inital =
value of the Cancel property on the event when passed in, but this isn't =
really called out in the documentation.

"Michael Giagnocavo [MVP]" <mggUNSPAM@Atrevido.net> wrote in message =
news:u4E4aPPpDHA.1284@TK2MSFTNGP09.phx.gbl...
Where's the e.Cancel =3D true;?

-mike
MVP

"Tom Briese" <tbriese@artemisalliance.com> wrote in message =
news:%23DGtIoLpDHA.2772@TK2MSFTNGP10.phx.gbl...
When using an event with a delegate type of CancelEventHandler, =
shouldn't the delegate be checking to see if the Cancel property on the =
event object has been set to true and stop execution upon the first =
'cancel' it encounters? It seems you will only get the cancel =
information for the last event hanlder to process, and all previous are =
effectively ignored.

Am I missing something?

Here is a quick example to show what I mean:

public class MyForm : Form {
public event CancelEventHandler MyCancelEvent;

private void CancelHandlerOne(object sender, CancelEventArgs e) {
System.Diagnostics.Debug.WriteLine("Handler 1: Event.Cancel =
passed in is " + e.Cancel.ToString());
}


private void CancelHandlerTwo(object sender, CancelEventArgs e) {
System.Diagnostics.Debug.WriteLine("Handler 2: Event.Cancel =
passed in is " + e.Cancel.ToString());
System.Diagnostics.Debug.WriteLine("Handler 2: Setting =
Event.Cancel to " + bool.TrueString);
}

private void CancelHandlerThree(object sender, CancelEventArgs e) =
{
System.Diagnostics.Debug.WriteLine("Handler 3: Event.Cancel =
passed in is " + e.Cancel.ToString());
}

private void MyForm_Load(object sender, System.EventArgs e) {
MyCancelEvent +=3D new CancelEventHandler(CancelHandlerOne);
MyCancelEvent +=3D new CancelEventHandler(CancelHandlerTwo);
MyCancelEvent +=3D new CancelEventHandler(CancelHandlerThree);
}

private void button1_Click(object sender, System.EventArgs e) {
CancelEventArgs evt =3D new CancelEventArgs(false);
if (MyCancelEvent !=3D null)
MyCancelEvent(this, evt);
System.Diagnostics.Debug.WriteLine("Event.Cancel after event =
call is " + evt.Cancel.ToString());
}

Pressing the button produces the following output:

Handler 1: Event.Cancel passed in is False
Handler 2: Event.Cancel passed in is False
Handler 2: Setting Event.Cancel to True
Handler 3: Event.Cancel passed in is False
Event.Cancel after event call is False

------=_NextPart_000_0009_01C3A514.155E33D0
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1264" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Sorry, yes I failed to include the =
setting of the=20
value.&nbsp; The event handlers should look like:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; private void =

CancelHandlerTwo(object sender, CancelEventArgs e)=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
System.Diagnostics.Debug.WriteLine("Handler=20
2: Event.Cancel passed in is " +=20
e.Cancel.ToString());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
System.Diagnostics.Debug.WriteLine("Handler 2: Setting Event.Cancel to " =
+=20
bool.TrueString);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.Cancel =3D=20
true;<BR>&nbsp;&nbsp;&nbsp; }</FONT></DIV>
<DIV><FONT face=3D"Courier New" size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3D"Courier New" size=3D2>&nbsp;&nbsp;&nbsp; private void =

CancelHandlerThree(object sender, CancelEventArgs e)=20
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
System.Diagnostics.Debug.WriteLine("Handler=20
3: Event.Cancel passed in is " +=20
e.Cancel.ToString());<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
System.Diagnostics.Debug.WriteLine("Handler 3: Setting Event.Cancel to " =
+=20
bool.FalseString);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; e.Cancel =3D=20
false;<BR>&nbsp;&nbsp;&nbsp; }<BR></FONT></DIV>
<DIV><FONT face=3DArial size=3D2>And the output would then =
be:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<BLOCKQUOTE dir=3Dltr style=3D"MARGIN-RIGHT: 0px">
<DIV><FONT face=3D"Courier New" size=3D2>Handler 1: Event.Cancel =
passed in is=20
False<BR>Handler 2: Event.Cancel passed in is False<BR>Handler 2: =
Setting=20
Event.Cancel to True<BR>Handler 3: Event.Cancel passed in is =
True<BR>Handler=20
3: Setting Event.Cancel to False<BR>Event.Cancel after event call is=20
False<BR></FONT><FONT face=3DArial size=3D2></FONT></DIV></BLOCKQUOTE>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>I guess each handler could =
take=20
responsibility for inspecting the inital value of the Cancel property on =
the=20
event when passed in, but this isn't really called out in the=20
documentation.</FONT></DIV>
<DIV dir=3Dltr><FONT face=3DArial size=3D2>&nbsp;</DIV></FONT>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV>"Michael Giagnocavo [MVP]" &lt;<A=20
href=3D"mailto:mggUNSPAM@Atrevido.net">mggUNSPAM@Atrevido.net</A>&gt; =
wrote in=20
message <A=20
=
href=3D"news:u4E4aPPpDHA.1284@TK2MSFTNGP09.phx.gbl">news:u4E4aPPpDHA.1284=
@TK2MSFTNGP09.phx.gbl</A>...</DIV>
<DIV><FONT face=3DArial size=3D2>Where's the e.Cancel =3D =
true;?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>-mike</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>MVP</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>"Tom Briese" &lt;<A=20
=
href=3D"mailto:tbriese@artemisalliance.com">tbriese@artemisalliance.com</=
A>&gt;=20
wrote in message <A=20
=
href=3D"news:%23DGtIoLpDHA.2772@TK2MSFTNGP10.phx.gbl">news:%23DGtIoLpDHA.=
2772@TK2MSFTNGP10.phx.gbl</A>...</DIV>
<BLOCKQUOTE dir=3Dltr=20
style=3D"PADDING-RIGHT: 0px; PADDING-LEFT: 5px; MARGIN-LEFT: 5px; =
BORDER-LEFT: #000000 2px solid; MARGIN-RIGHT: 0px">
<DIV><FONT face=3DArial size=3D2>When using an event with a delegate =
type of=20
CancelEventHandler, shouldn't the delegate be checking to see if the =
Cancel=20
property on the event object has been set to true and stop execution =
upon=20
the first 'cancel' it encounters?&nbsp; It seems you will only get=20
the&nbsp;cancel information for&nbsp;the last event hanlder to =
process, and=20
all previous are effectively ignored.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Am I missing =
something?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Here is a quick example to show =
what I=20
mean:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV>
<P><FONT face=3D"Courier New" size=3D2>public class MyForm : Form =
{<BR>&nbsp;=20
public event CancelEventHandler MyCancelEvent;</FONT></P>
<P><FONT face=3D"Courier New" size=3D2>&nbsp; private void=20
CancelHandlerOne(object sender, CancelEventArgs e) =
{<BR>&nbsp;&nbsp;&nbsp;=20
</FONT><FONT face=3D"Courier New"=20
size=3D2>System.Diagnostics.Debug.WriteLine("Handler 1: Event.Cancel =
passed in=20
is " + e.Cancel.ToString());<BR>&nbsp; </FONT><FONT face=3D"Courier =
New"=20
size=3D2>}</FONT></P>
<P><FONT face=3D"Courier New" size=3D2></FONT></P>
<P><FONT face=3D"Courier New" size=3D2>&nbsp; private void=20
CancelHandlerTwo(object sender, CancelEventArgs e) =
{<BR>&nbsp;&nbsp;&nbsp;=20
</FONT><FONT face=3D"Courier New"=20
size=3D2>System.Diagnostics.Debug.WriteLine("Handler 2: Event.Cancel =
passed in=20
is " + e.Cancel.ToString());<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT=20
face=3D"Courier New" =
size=3D2>System.Diagnostics.Debug.WriteLine("Handler 2:=20
Setting Event.Cancel to " + bool.TrueString);<BR>&nbsp; </FONT><FONT =

face=3D"Courier New" size=3D2>}</FONT></P>
<P><FONT face=3D"Courier New" size=3D2>&nbsp; private void=20
CancelHandlerThree(object sender, CancelEventArgs e) =
{<BR>&nbsp;&nbsp;&nbsp;=20
</FONT><FONT face=3D"Courier New"=20
size=3D2>System.Diagnostics.Debug.WriteLine("Handler 3: Event.Cancel =
passed in=20
is " + e.Cancel.ToString());<BR>&nbsp; </FONT><FONT face=3D"Courier =
New"=20
size=3D2>}</FONT></P>
<P><FONT face=3D"Courier New" size=3D2>&nbsp; private void =
MyForm_Load(object=20
sender, System.EventArgs e) {<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT=20
face=3D"Courier New" size=3D2>MyCancelEvent +=3D new=20
CancelEventHandler(CancelHandlerOne);<BR>&nbsp;&nbsp;&nbsp; =
</FONT><FONT=20
face=3D"Courier New" size=3D2>MyCancelEvent +=3D new=20
CancelEventHandler(CancelHandlerTwo);<BR>&nbsp;&nbsp;&nbsp; =
</FONT><FONT=20
face=3D"Courier New" size=3D2>MyCancelEvent +=3D new=20
CancelEventHandler(CancelHandlerThree);<BR>&nbsp; </FONT><FONT=20
face=3D"Courier New" size=3D2>}</FONT></P>
<P><FONT face=3D"Courier New" size=3D2>&nbsp; private void =
button1_Click(object=20
sender, System.EventArgs e) {<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT=20
face=3D"Courier New" size=3D2>CancelEventArgs evt =3D new=20
CancelEventArgs(false);<BR>&nbsp;&nbsp;&nbsp; </FONT><FONT=20
face=3D"Courier New" size=3D2>if (MyCancelEvent !=3D=20
null)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </FONT><FONT face=3D"Courier =
New"=20
size=3D2>MyCancelEvent(this, evt);<BR>&nbsp;&nbsp;&nbsp; =
</FONT><FONT=20
face=3D"Courier New" =
size=3D2>System.Diagnostics.Debug.WriteLine("Event.Cancel=20
after event call is " + evt.Cancel.ToString());<BR>&nbsp; =
</FONT><FONT=20
face=3D"Courier New" size=3D2>}</FONT></P>
<P><FONT face=3DArial size=3D2>Pressing the button produces the =
following=20
output:</FONT></P><FONT size=3D1>
<P><FONT face=3D"Courier New" size=3D2>Handler 1: Event.Cancel =
passed in is=20
False<BR></FONT><FONT face=3D"Courier New" size=3D2>Handler 2: =
Event.Cancel=20
passed in is False<BR></FONT><FONT face=3D"Courier New" =
size=3D2>Handler 2:=20
Setting Event.Cancel to True<BR></FONT><FONT face=3D"Courier New"=20
size=3D2>Handler 3: Event.Cancel passed in is False<BR></FONT><FONT=20
face=3D"Courier New" size=3D2>Event.Cancel after event call is=20
=
False</FONT></P></FONT></DIV></BLOCKQUOTE></BLOCKQUOTE></BODY></HTML>

------=_NextPart_000_0009_01C3A514.155E33D0--