We special cased setting AcceptButton and CancelButton in order to make
the designtime a "one click" operation - rather than having to set the
DialogResult and then then the CancelButton or vice versa you just have
to set the CancelButton. The typical case is that you want the
CancelButton to close the form with a DialogResult of Cancel. Thus the
behavior you see today. The typical case is the smallest number of steps
but you can still do the atypical case. Unfortunately we muddied this at
some point by changing the behavior of the AcceptButton and did not keep
the AcceptButton and CancelButton consistent. We should not have changed
the AcceptButton behavior. With the way it is today I've seen more
questions along the lines of "I set the AcceptButton on my form and it
does not close the form" than I have "I set the CancelButton on the form
and it still closes"
mark

-----Original Message-----
From: Chris Sells [mailto:[EMAIL PROTECTED]] 
Sent: Tuesday, June 11, 2002 7:55 AM
To: [EMAIL PROTECTED]
Subject: Re: [DOTNET] Why is CancelButton special?

I don't (yet) want pressing the Cancel button to not close the form, but
that wasn't my question. WinForms has a nice architecture for setting
the
DialogResult for a button and either having the form close or not when
the
button is pressed based on whether they DialogResult property for that
button is set, but they had to go and special case it for Cancel. Seems
like
a waste of a perfectly good architecture.

Chris
----- Original Message -----
From: "Ian Griffiths" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, June 11, 2002 2:49 AM
Subject: Re: [DOTNET] Why is CancelButton special?


> As far as I can tell the purpose of having a CancelButton is to close
the
> form for you automatically whatever.  If you don't want this behaviour
don't
> assign a CancelButton!
>
> By the way having the DialogResult as None is handled as a special
case.
If
> you set the DialogResult to be anything else then Windows Forms will
return
> whatever you specify as the DialogResult.  But if your CancelButton
> specifies None it returns Cancel anyway!  (But I think it always
closes
the
> form.)
>
> Why do you want something to be a CancelButton but not have it close
the
> form?  Is there something else that CancelButton does for you?
>
> --
> Ian Griffiths
> DevelopMentor
>
> ----- Original Message -----
> From: "Chris Sells" <[EMAIL PROTECTED]>
>
>
> > If I set the AcceptButton to a button whose DialogResult is set to
None,
> > pressing that button does not automatically close the form.
> >
> > However, if I set the CancelButton to a button whose DialogResult is
set
> > to None, pressing the button *does* automatically close the form and
I
> > don't see any way to halt this process, even if I've got an event
> > handler for that button. Why is that?

You can read messages from the DOTNET archive, unsubscribe from DOTNET,
or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to