views:

745

answers:

2

Hi,

I want to do my own action on tap (click) to close button ( X in right top corner ) in compact framework appliaction. I'm using Windows Mobile 6.1.

Usualy I want default behaviour, but sometimes I want to change the usercontrol on current form. How can I reach it?

Thanks!

+1  A: 

If I understand what you want to do:

private void Form1_Closing(object sender, CancelEventArgs e)
{
     e.Cancel = true;
     //Do my own thing
}

You can provide and event handler for the "Closing" event of a form. By e.Cancel = true you say that you don't want the form to close, and then you can do whatever else you want to do.

Petros
If I set MinimizeBox = false (as @ctacke wrote) then is this event fired. Thanks.
TcKs
+1  A: 

The (X) button is not a Close button, it is a Smart Minimize button, and you can't directly hook into it (You will get a Deactivated event probably, but you can't cancel that).

You can change the MinimizeButton property of the Form to false and it will change to an (ok) button, which you can handle (as Petros points out). You can likely use an IMessageFilter or subclass the form to hook its WinProc to also get hold of the minimize event as well.

See also:

ctacke
Thanks, I'll try change MinimizeButton property and hook the Close event.
TcKs