How to change the top-right "X" button to "OK" ?

Z

ZhangZQ

How can I change the top-right "X" button of a form to "OK", and how to
handle the event of that button?

I know the form shown by ShowDialog method will change the "X" button to
"OK", but I my application, there is only one form, there are many UI
component in that form, and those UI component will be shown depends on the
event of "X" button.



Thanks,
ZhangZQ
 
T

Tim Wilson

Set the Forms "MinimizeBox" property to false. You can handle the closing of
the Form using the Closing or Closed event.
 
Z

ZhangZQ

Tim Wilson,

Thank you very much! That is what I need, but clicking the "OK" button now
will cause the program to exit, how can I prevent the program to exit in the
body of "private void Form1_Closing(object sender,
System.ComponentModel.CancelEventArgs e)" ?


Thanks,
ZhangZQ
 
T

Tim Wilson

If you close the startup Form the application will exit. So in this
situation, if you need to keep the Form "alive" for some reason then you can
set the "Cancel" property of the CancelEventArgs object that is passed to
the event handler to true.

e.Cancel = true;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top