Prevent Closing of a ToolWindow

Docking/MDI for Windows Forms Forum

Posted 16 years ago by Miriam Kuruvilla
Version: 2.0.0100
Avatar
I want to be able to control the closing of a toolwindow, so that it only closes when a menu item is clicked. i.e I want to disable closing of the tool window using the x button.

When I create a new ToolWindow, I set the toolWindow.CanClose = false.
Then right away, I call toolWindow.Undock(), so it appears undocked.

However, in the undocked state, the ToolWindow still displays the x button in the TitleBar, giving users the illusion that it can be closed. When you click on the x button, it does nothing because the CanClose property is set to false.
This is misleading. How can I get rid of the x button?

Alternatively:
I also tried setting ToolWindow.CanClose = true,
Then in the ToolWindow_Closing event I set
e.Cancel = true;
toolWindow.Hide();

This hides the control in the ToolWindow, but the form itself is still visible.

What is the right approach?

Comments (5)

Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Right now there isn't a way to remove that button the floating container. Thanks I'll write this down on the TODO list.


Actipro Software Support

Posted 16 years ago by Miriam Kuruvilla
Avatar
Thanks...that would be great.

In the meantime, do you have any suggestions as to how I can get the ToolWindow to Hide when the user clicks on the x button ( with CanClose set to true)?

I did try handling the ToolWindow_Closing event as below.

void ToolWindow_Closing(object sender, TabbedMdiWindowClosingEventArgs e)
{
    if (e.Reason == TabbedMdiWindowCloseReason.User)
    {
        e.Cancel = true;
        //this.ToolWindowContainer.Hide();
        //this.Hide();
    }
}
If I call ToolWindow.Hide(), the form is still displayed and the control on the form is hidden. Tried to use ToolWindowContainer.Hide() as well, but the effect is the same.
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
I'm a bit confused by your code sample here. You are cancelling the Close by saying e.Cancel, but then trying to manually close it. So why not just let it go through instead of doing this code?

But you shouldn't call Hide() in the Closing method. The Closing method was called in reponsed to a Hide() method call either via programmatically or by a user action. Hide is the same thing as a "close" when talking in terms of a tool window.


Actipro Software Support

Posted 16 years ago by Miriam Kuruvilla
Avatar
Thanks for clarifying that. I was under the assumption that Closing a ToolWindow would remove it from the ToolWindowCollection.
Using Close() and Activate() to hide/show the ToolWindow works very well.
Posted 16 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Tool windows will always remain in the DockManager until you manually remove them. Document windows on the other hand will by default be removed and disposed when they are closed, however you can prevent this behavior by a DockManager option.


Actipro Software Support

The latest build of this product (v24.1.0) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.