Desktop Toolbar application use with message boxes

I am current developing a WinForm app that contain's a form that may be docked on the desktop, in a similar manner to the task bar. This uses the SHAppBarMessage API, and is based on the sample app posted on this site by Fred Balsiger.

I want to display a 'Are you sure?' message box on closing. To do this I have added an event handler to the Form_Closing event. When I close the form while it is docked, as it displays the message box, it loses the docking. The form stays where it is (i.e. at the top of the screen), but other items on the desk top move over the form (e.g. if there is a maximized window open, it expands over the toolbar app)

Can anybody explian why this could be happening, and how to stop it?

[722 byte] By [codefund.com] at [2007-12-16]
# 1
Hi Robin, I think the problem here is that at the time you're trying to cancel the closing - the AppBar has already unregistered itself.

With the sample I posted, try adding your MessageBox code to the "Close" button's click event instead of responding to the OnClosing notification. Something like this...

//Close_button_click_event {

DialogResult res = MessageBox.Show("Are you sure you want to close?", "Close?", MessageBoxButtons.OKCancel);
if (res == DialogResult.OK)
{
this.Close();
}

//end Close_button_click_event

...this should work much better for you.

Good luck,
-Fred

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...
# 2
You're absolutely right Fred, I forgot about the override to the onClosing method which unregisters the app - this must have been called before the closing event handler, presumably because the event handler is triggered when the base.onClosing method is called.

Anyway, I put attached the message box to the close button event as you suggested and it worked like a dream.

Thanks very much for posting your sample app - it has been very useful for me.

Regards

Robin

codefund.com at 2007-9-8 > top of Msdn Tech,Windows Forms,Windows Forms General...