PC Review


Reply
Thread Tools Rate Thread

Cancel a click event on a button

 
 
Gallarpri
Guest
Posts: n/a
 
      17th Jan 2007
Hi, I'm making a dialog form with a textbox and 2 buttons: OK and
Cancel.

I want when I click on OK button, the program check the textbox, and if
there is any error in the text introduced there, then it shows a
MessageBox and cancel the click event, so the dialog form won't close.

How can I cancel the click event on a button? I have looked at
"EventArgs e", but it hasnt any property to cancel the vent.

Thank you!
Jose.

 
Reply With Quote
 
 
 
 
Fabrizio Romano
Guest
Posts: n/a
 
      17th Jan 2007
You don't need to cancel the click event.
I would do like this:
Handle the textbox validation event. If there are some error then just
inform the user, otherwise set the form's DialogResult property to Ok.
Do it manually without setting it visually, otherwise it will always close.

HTH
Fabrizio

"Gallarpri" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi, I'm making a dialog form with a textbox and 2 buttons: OK and
> Cancel.
>
> I want when I click on OK button, the program check the textbox, and if
> there is any error in the text introduced there, then it shows a
> MessageBox and cancel the click event, so the dialog form won't close.
>
> How can I cancel the click event on a button? I have looked at
> "EventArgs e", but it hasnt any property to cancel the vent.
>
> Thank you!
> Jose.
>



 
Reply With Quote
 
Gallarpri
Guest
Posts: n/a
 
      17th Jan 2007
Thanks for answering.

I have finally resolved it putting the DialogResult property of the OK
button to "None", so the form doesnt close now when I click on this
button. I do the check, and if all its correct, then I call
this.Close()

Hope it helps to someone too

 
Reply With Quote
 
Michael Voss
Guest
Posts: n/a
 
      18th Jan 2007
Gallarpri wrote:

[...snip...]
> I have finally resolved it putting the DialogResult property of the OK
> button to "None", so the form doesnt close now when I click on this
> button. I do the check, and if all its correct, then I call
> this.Close()

[...snip...]

As Fabrizio mentioned, set the DialogResult property of your Form to
DialogResult.OK before closing, so you can find out wether your user clicked
on "OK" or "Cancel"....



 
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
How to Cancel a Cancel Button event Eric T. Microsoft Dot NET Framework Forms 3 5th Feb 2009 11:36 PM
stumped...table row click event and then cancel the checkbox click =?Utf-8?B?ZGF2ZQ==?= Microsoft Dot NET 1 2nd Sep 2006 03:53 AM
How to fire both event button click and textchanged when button is click and text is changed Amy Microsoft ASP .NET 0 1st Jun 2006 03:33 PM
When I click the cancel button of the DataGrid control, it raises DeleteCommand event!!! Why???????? XueWu Microsoft ASP .NET 0 12th Jul 2005 02:42 PM
Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl. jorge Microsoft ASP .NET 2 26th May 2004 12:45 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:41 AM.