1

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!

TcKs
  • 25,849
  • 11
  • 66
  • 104

3 Answers3

3

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:

Community
  • 1
  • 1
ctacke
  • 66,480
  • 18
  • 94
  • 155
2

The function you are looking for is SHDoneButton.

Calling it with a dwState of SHDB_SHOWCANCEL changes the behavior of the "Smart Minimize" button to merely emitting a WM_COMMAND message. Then, you just need to listen for the WM_COMMAND message by setting a custom WndProc.

Community
  • 1
  • 1
jtdubs
  • 13,585
  • 1
  • 17
  • 12
  • 1
    Note the ".net" tag on the question. – ctacke Nov 16 '10 at 19:16
  • 1
    To my knowledge, this problem can't be solved with pure .NET. The relevant calls are not exposed. The answer is to use PInvoke. Note that my "setting a custom WndProc" link is to a C# post. – jtdubs Nov 18 '10 at 02:03
  • @jtdubs Could you please elaborate on this within your answer? The Q is about solving this with .NET. – Brian Lacy Sep 18 '18 at 22:07
1

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
  • 8,862
  • 3
  • 39
  • 38
  • 1
    If I set MinimizeBox = false (as @ctacke wrote) then is this event fired. Thanks. – TcKs Mar 25 '09 at 10:00