PC Review


Reply
Thread Tools Rate Thread

How to create a form with the equivalent of a Cancel Button

 
 
Roy Chastain
Guest
Posts: n/a
 
      6th Mar 2004
If I just create a new form in CF, I get the default OK in the upper
right corner. That is fine, but what if I want the user to be able to
cancel his request.

What is the correct design and what is the correct mechanics to
provide a :"I don't really want to do this" type operation?

Thanks
-------------------------------------------
Roy Chastain
 
Reply With Quote
 
 
 
 
Tim Wilson
Guest
Posts: n/a
 
      6th Mar 2004
I take it you are developing with a device running PPC 2000, as starting
with devices running PPC 2002 you must set MinimizeBox = False on the Form
in order to get the Ok button shown. So if you rely on the Ok button being
in the caption bar for your Form then you will need to set MinimizeBox =
False so that the default behavior for your app is the same on newer PPC
devices as well. But to answer your question (hopefully) you can handle the
Closing event for the Form and set the Cancel property on the event args
object that is passed to your event handler.

private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)
{
if (MessageBox.Show("Do you want to close?", "Close",
MessageBoxButtons.OKCancel, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2) == DialogResult.Cancel)
{
e.Cancel = true;
}
}

--
Tim Wilson
..Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}
"Roy Chastain" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> If I just create a new form in CF, I get the default OK in the upper
> right corner. That is fine, but what if I want the user to be able to
> cancel his request.
>
> What is the correct design and what is the correct mechanics to
> provide a :"I don't really want to do this" type operation?
>
> Thanks
> -------------------------------------------
> Roy Chastain



 
Reply With Quote
 
Peter Foot [MVP]
Guest
Posts: n/a
 
      6th Mar 2004
You can add a button to the form and in its click handler set the
DialogResult of the form to DialogResult.Cancel to indicate a cancel
operation to a calling form. Unlike the OK button which is unique there is
no specific cancel equivalent.

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org

"Roy Chastain" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> If I just create a new form in CF, I get the default OK in the upper
> right corner. That is fine, but what if I want the user to be able to
> cancel his request.
>
> What is the correct design and what is the correct mechanics to
> provide a :"I don't really want to do this" type operation?
>
> Thanks
> -------------------------------------------
> Roy Chastain



 
Reply With Quote
 
Roy Chastain
Guest
Posts: n/a
 
      6th Mar 2004
Thanks to both of you.

After I posted, I found the DialogResult property of the button.
I simply set my cancel button to DialogResult.Cancel and my OK button
to DialogResult.OK, in the constructor for the form after the
InitializeComponent was called.

Then I do a ShowDialog and check result to DialogResult.OK or .cancel.
This appears to work. Not click handlers required etc. Is this BAD?
Did I miss something?

BTW. I am currently using emulator for 2002 and the OK appears by
default on the new form. It also returns a DialogResult.OK from the
ShowDialog.

Thanks

On Sat, 6 Mar 2004 19:54:45 -0000, "Peter Foot [MVP]"
<(E-Mail Removed)> wrote:

>You can add a button to the form and in its click handler set the
>DialogResult of the form to DialogResult.Cancel to indicate a cancel
>operation to a calling form. Unlike the OK button which is unique there is
>no specific cancel equivalent.
>
>Peter


-------------------------------------------
Roy Chastain
 
Reply With Quote
 
Tim Wilson
Guest
Posts: n/a
 
      6th Mar 2004
No, that sounds like the way to go. I think I just misunderstood exactly
what you were trying to do. I thought that you wanted to perhaps ask the
user if he/she wanted to cancel after the Ok was clicked. Something like
"Are you sure that you want to save changes?". This is when you would
require a Closing event handler.

> BTW. ...

If you are showing the Form with ShowDialog then you will get the Ok. But if
you show the Form using the Show method, with PPC 2002 and later, you will
get a "smart minimize button" by default instead. I wasn't sure what call
you were making (Show or ShowDialog) so I thought that I would at least
point out the difference in behavior from PPC 2000 to PPC 2002. In this case
it doesn't really sound like it is an issue.

--
Tim Wilson
..Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}
"Roy Chastain" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks to both of you.
>
> After I posted, I found the DialogResult property of the button.
> I simply set my cancel button to DialogResult.Cancel and my OK button
> to DialogResult.OK, in the constructor for the form after the
> InitializeComponent was called.
>
> Then I do a ShowDialog and check result to DialogResult.OK or .cancel.
> This appears to work. Not click handlers required etc. Is this BAD?
> Did I miss something?
>
> BTW. I am currently using emulator for 2002 and the OK appears by
> default on the new form. It also returns a DialogResult.OK from the
> ShowDialog.
>
> Thanks
>
> On Sat, 6 Mar 2004 19:54:45 -0000, "Peter Foot [MVP]"
> <(E-Mail Removed)> wrote:
>
> >You can add a button to the form and in its click handler set the
> >DialogResult of the form to DialogResult.Cancel to indicate a cancel
> >operation to a calling form. Unlike the OK button which is unique there

is
> >no specific cancel equivalent.
> >
> >Peter

>
> -------------------------------------------
> Roy Chastain



 
Reply With Quote
 
Peter Foot [MVP]
Guest
Posts: n/a
 
      6th Mar 2004
One way for a consistent appearance on all versions (and I think also to
obey one of the design guidelines) if you have both an OK and Cancel button
you can disable the ControlBox of the form and neither the OK or X button
will be shown - you can then have your Ok and Cancel buttons at the bottom
of the form setup with the relevant DialogResults. A number use this sort of
approach (e.g. the new email account wizard)

Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org

"Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
news:(E-Mail Removed)...
> No, that sounds like the way to go. I think I just misunderstood exactly
> what you were trying to do. I thought that you wanted to perhaps ask the
> user if he/she wanted to cancel after the Ok was clicked. Something like
> "Are you sure that you want to save changes?". This is when you would
> require a Closing event handler.
>
> > BTW. ...

> If you are showing the Form with ShowDialog then you will get the Ok. But

if
> you show the Form using the Show method, with PPC 2002 and later, you will
> get a "smart minimize button" by default instead. I wasn't sure what call
> you were making (Show or ShowDialog) so I thought that I would at least
> point out the difference in behavior from PPC 2000 to PPC 2002. In this

case
> it doesn't really sound like it is an issue.
>
> --
> Tim Wilson
> .Net Compact Framework MVP
> {cf147fdf-893d-4a88-b258-22f68a3dbc6a}
> "Roy Chastain" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Thanks to both of you.
> >
> > After I posted, I found the DialogResult property of the button.
> > I simply set my cancel button to DialogResult.Cancel and my OK button
> > to DialogResult.OK, in the constructor for the form after the
> > InitializeComponent was called.
> >
> > Then I do a ShowDialog and check result to DialogResult.OK or .cancel.
> > This appears to work. Not click handlers required etc. Is this BAD?
> > Did I miss something?
> >
> > BTW. I am currently using emulator for 2002 and the OK appears by
> > default on the new form. It also returns a DialogResult.OK from the
> > ShowDialog.
> >
> > Thanks
> >
> > On Sat, 6 Mar 2004 19:54:45 -0000, "Peter Foot [MVP]"
> > <(E-Mail Removed)> wrote:
> >
> > >You can add a button to the form and in its click handler set the
> > >DialogResult of the form to DialogResult.Cancel to indicate a cancel
> > >operation to a calling form. Unlike the OK button which is unique there

> is
> > >no specific cancel equivalent.
> > >
> > >Peter

> >
> > -------------------------------------------
> > Roy Chastain

>
>



 
Reply With Quote
 
Tim Wilson
Guest
Posts: n/a
 
      6th Mar 2004
And another that I might suggest, if it makes sense in the context of the
application, is to create two top level entries on the MainMenu - one that
says "Ok" and one that says "Cancel". You could also use the ToolBar and
specify pictures on the menu, if that might mean more to the end-user.

--
Tim Wilson
..Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}
"Peter Foot [MVP]" <(E-Mail Removed)> wrote in message
news:edS6%(E-Mail Removed)...
> One way for a consistent appearance on all versions (and I think also to
> obey one of the design guidelines) if you have both an OK and Cancel

button
> you can disable the ControlBox of the form and neither the OK or X button
> will be shown - you can then have your Ok and Cancel buttons at the bottom
> of the form setup with the relevant DialogResults. A number use this sort

of
> approach (e.g. the new email account wizard)
>
> Peter
>
> --
> Peter Foot
> Windows Embedded MVP
> OpenNETCF.org Senior Advisor
> www.inthehand.com | www.opennetcf.org
>
> "Tim Wilson" <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote in message
> news:(E-Mail Removed)...
> > No, that sounds like the way to go. I think I just misunderstood exactly
> > what you were trying to do. I thought that you wanted to perhaps ask the
> > user if he/she wanted to cancel after the Ok was clicked. Something like
> > "Are you sure that you want to save changes?". This is when you would
> > require a Closing event handler.
> >
> > > BTW. ...

> > If you are showing the Form with ShowDialog then you will get the Ok.

But
> if
> > you show the Form using the Show method, with PPC 2002 and later, you

will
> > get a "smart minimize button" by default instead. I wasn't sure what

call
> > you were making (Show or ShowDialog) so I thought that I would at least
> > point out the difference in behavior from PPC 2000 to PPC 2002. In this

> case
> > it doesn't really sound like it is an issue.
> >
> > --
> > Tim Wilson
> > .Net Compact Framework MVP
> > {cf147fdf-893d-4a88-b258-22f68a3dbc6a}
> > "Roy Chastain" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Thanks to both of you.
> > >
> > > After I posted, I found the DialogResult property of the button.
> > > I simply set my cancel button to DialogResult.Cancel and my OK button
> > > to DialogResult.OK, in the constructor for the form after the
> > > InitializeComponent was called.
> > >
> > > Then I do a ShowDialog and check result to DialogResult.OK or .cancel.
> > > This appears to work. Not click handlers required etc. Is this BAD?
> > > Did I miss something?
> > >
> > > BTW. I am currently using emulator for 2002 and the OK appears by
> > > default on the new form. It also returns a DialogResult.OK from the
> > > ShowDialog.
> > >
> > > Thanks
> > >
> > > On Sat, 6 Mar 2004 19:54:45 -0000, "Peter Foot [MVP]"
> > > <(E-Mail Removed)> wrote:
> > >
> > > >You can add a button to the form and in its click handler set the
> > > >DialogResult of the form to DialogResult.Cancel to indicate a cancel
> > > >operation to a calling form. Unlike the OK button which is unique

there
> > is
> > > >no specific cancel equivalent.
> > > >
> > > >Peter
> > >
> > > -------------------------------------------
> > > Roy Chastain

> >
> >

>
>



 
Reply With Quote
 
Roy Chastain
Guest
Posts: n/a
 
      6th Mar 2004
Again thanks to both Tim and Peter.

Tim,
The application has a main form that has a tab control (at least for
now). The form in question comes up in response to use action on the
main form. Are you suggesting that I add a menu to the secondary form
with an OK and Cancel on it?

I am not sure that I have seen this design on other programs, but I
will admit that I have very few add on programs on my PPC. Is this a
interface paradigm that the users are getting used to?

On Sat, 6 Mar 2004 16:53:47 -0500, "Tim Wilson"
<TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote:

>And another that I might suggest, if it makes sense in the context of the
>application, is to create two top level entries on the MainMenu - one that
>says "Ok" and one that says "Cancel". You could also use the ToolBar and
>specify pictures on the menu, if that might mean more to the end-user.


-------------------------------------------
Roy Chastain
 
Reply With Quote
 
Tim Wilson
Guest
Posts: n/a
 
      6th Mar 2004
> Is this a interface paradigm that the users
> are getting used to?

Not that I know of This is just a way that I have used before as it does
free up some space on the Form for other things. If the Form is really tight
on space then it's an option to move the Ok/Cancel from Button's to the
MainMenu. I didn't mean to imply that this is standard, or even becoming
standard. It's simply an option that might be considered depending on what
you feel is best for the end-user in the given situation. Standards and
guidelines are there as a recommendation that allows users to sometimes
reduce the learning curve associated with an application. However, depending
on your target audience, you might decide to differ from the
recommendations. The end-user (customer) is the one that needs to live with
the application. So whatever seems right for them is probably the best
solution - and that is not always the standard way. I just wanted to present
another option that you might consider.

--
Tim Wilson
..Net Compact Framework MVP
{cf147fdf-893d-4a88-b258-22f68a3dbc6a}
"Roy Chastain" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Again thanks to both Tim and Peter.
>
> Tim,
> The application has a main form that has a tab control (at least for
> now). The form in question comes up in response to use action on the
> main form. Are you suggesting that I add a menu to the secondary form
> with an OK and Cancel on it?
>
> I am not sure that I have seen this design on other programs, but I
> will admit that I have very few add on programs on my PPC. Is this a
> interface paradigm that the users are getting used to?
>
> On Sat, 6 Mar 2004 16:53:47 -0500, "Tim Wilson"
> <TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote:
>
> >And another that I might suggest, if it makes sense in the context of the
> >application, is to create two top level entries on the MainMenu - one

that
> >says "Ok" and one that says "Cancel". You could also use the ToolBar and
> >specify pictures on the menu, if that might mean more to the end-user.

>
> -------------------------------------------
> Roy Chastain



 
Reply With Quote
 
Roy Chastain
Guest
Posts: n/a
 
      6th Mar 2004
Again thanks Tim.
I understand and agree with what you are saying. My concept if there
is not a good reason then don't stray too far from the design
guidelines. It does reduce the learning curve.

I appreciate the idea of the OK and Cancel on the menu. As you say
that could be a good trick for a crowded form. I will keep that one
in the back of my mind. At this point I don't need it, this form is
very empty. I am sure that will change as time goes on.

On Sat, 6 Mar 2004 17:23:48 -0500, "Tim Wilson"
<TIM(UNDERSCORE)WILSON(AT)ROGERS(PERIOD)COM> wrote:

>> Is this a interface paradigm that the users
>> are getting used to?

>Not that I know of This is just a way that I have used before as it does
>free up some space on the Form for other things. If the Form is really tight
>on space then it's an option to move the Ok/Cancel from Button's to the
>MainMenu. I didn't mean to imply that this is standard, or even becoming
>standard. It's simply an option that might be considered depending on what
>you feel is best for the end-user in the given situation. Standards and
>guidelines are there as a recommendation that allows users to sometimes
>reduce the learning curve associated with an application. However, depending
>on your target audience, you might decide to differ from the
>recommendations. The end-user (customer) is the one that needs to live with
>the application. So whatever seems right for them is probably the best
>solution - and that is not always the standard way. I just wanted to present
>another option that you might consider.


-------------------------------------------
Roy Chastain
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Create "cancel" button on a form collecting parameters anders bitzer Microsoft Access Getting Started 5 4th Jun 2010 12:33 PM
Custom button from a Control class doesn't appear as a choice for OK/Cancel button in a Form properties CroDude Microsoft C# .NET 3 28th Jun 2005 06:27 PM
How to Create progress bar with cancel button? david Microsoft Dot NET Framework Forms 2 17th Nov 2004 09:46 PM
Trying to create a cancel button. JFELLA Microsoft Access Forms 4 15th Apr 2004 12:14 AM
Create a Cancel Button MArend Microsoft Access Forms 5 31st Oct 2003 09:42 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:19 PM.