-
November 29th, 2006, 03:08 PM
#1
button event handler
I'm using Visual Studio 2005 Pro, and trying my hand at learning C#. I've been writing C and C++ code for quite a few years.
Problem #1: I put a button on a form that is supposed to exit the application. In C++ MFC I would just call CDialog::OnOK() event. Is there an equivalent in C#? If yes, what is it?
Problem #2: what books do you recommend for beginners moving from c++ to C#, or for C# windows programming in general? Any good links other than amazon.com?
Thanks
-
November 29th, 2006, 03:29 PM
#2
Re: button event handler
#1: Application.Exit() will gracefully exit all message pumps, or Close() on "main" form will work too if that is the only form receiving events.
-
November 29th, 2006, 03:36 PM
#3
Re: button event handler
The parts of "Windows Forms 2.0 Programming " by Sells and Weinhardt that I've read have been very useful. I haven't bought the book yet, but I probably will.
-
November 29th, 2006, 03:58 PM
#4
Re: button event handler
thank you both for timely responses.
-
November 29th, 2006, 05:00 PM
#5
Re: button event handler
the button you place on your form has a Click event. handle that event and add the click logic there. Each form has a DialogResult, and even when you assign the form's OK button to the one you've placed on the form, you must explicitly assign the forms' DialogResult property to OK inside your OK button's click event. Cancel will be set automatically when you click the cancel button (once you've set the forms cancel button on the form) but ok does not have the same behavior.
no recomendations on books.
also Application.Exit kills the app. it has the same effect as killing the application from process explorer. calling the Close method on the main form will cause the application to exit in a normal fashion.
-
November 29th, 2006, 05:36 PM
#6
Re: button event handler
Yep, MadHatter is right, when Close() is called on a Form events Form.Closed and Form.Closing will be fired, but not on Application.Exit().
Application.Exit() will stop all message loops and close all windows, but not stop the application. Instead it will cause the Application.Run() method to terminate, so after that (typically in your main), your program may do other things - but in most cases it will not.
-
November 29th, 2006, 05:47 PM
#7
Re: button event handler
actually I think in 2.0 they added a Form.FormClosing or Form.FormClosed or something like that that event that is supposed to fire on Application.Exit().
-
November 30th, 2006, 02:15 AM
#8
Re: button event handler
I recommend Professional C# 2005 which I think is a great book.
http://www.amazon.com/Professional-2.../dp/0764575341
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|