Sunday, February 24, 2008

Working with forms: How to hide the 'x' button or show an 'ok' button instead

A very common question when you start to work with forms and the .Net Compact Framework is how to replace the 'x' button on the title bar with an 'ok' button. By default, a new form is created showing an 'x' button, which is a minimize box on the title bar:

 image

In runtime, it behaves as a minimize button, when the user press this button the form is minimized. Sometimes we prefer to replace this button with an 'ok' button, as in a dialog. This is very easy. Just open the form on design mode and change the MinimizeBox property to false:

image

Now we have a new 'ok' button which will close the form in runtime setting the form DialogResult property to DialogResult.OK

image

If you want to hide both buttons, you can set the ControlBox property of the form to false.

image

Now the form doesn't have any buttons on the title bar.

image

Indeed, all these from properties can be changed programmatically from your code. It's really easy! Isn't it?

No comments: