This is a migrated thread and some comments may be shown as answers.

Is it possible to hide a floating document window?

1 Answer 33 Views
This is a migrated thread and some comments may be shown as answers.
Nicholas
Top achievements
Rank 1
Nicholas asked on 08 Mar 2018, 04:00 PM
How can I hide a floating document window? Right now it seems as though if you right-click, it gives you the option to be able to hide the window, but when you click on it, it doesn't really hide it, it closes it instead. When I switch the closeAction propery to hide, it seems like you can hide the window now. But when it's on the default behavior for closeaction which is closeanddispose, it just closes it. Is that what it's supposed to do? Is there a way to close the window when I hit the x and if I hide it, it actually hides it? I noticed that if I disable the option to hide (which AutoHide is already disabled), it disables the x in the corner of the window too. 

1 Answer, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 09 Mar 2018, 11:34 AM
Hi Nicholas,

Thank you for writing.

Whether a window will be hidden or closed is determined by its CloseAction property and the default value is CloseAndDispose. When hiding a floating window with CloseAction different than Hide it will close. This behavior is by design and it is desired. Additional information how the property works is available here: https://docs.telerik.com/devtools/winforms/dock/object-model/removing-toolwindow-and-documentwindow-at-runtime.

As I understand, you would like to have the floating hide when you choose Hide from the context menu and close when clicking the Close button. This can be accomplished by handling the ContextMenuItemClicked event of the context menu service and setting the CloseAction property of the window to Hide. When you show it, however, you will also need to restore the default value of the property so that you can close the window and not hide it when clicking the Close button. Please check my code snippet below: 
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
 
        ContextMenuService svc = this.radDock1.GetService<ContextMenuService>();
        svc.ContextMenuItemClicked += Svc_ContextMenuItemClicked;
    }
    private void Svc_ContextMenuItemClicked(object sender, ContextMenuItemClickEventArgs e)
    {
        DockWindow window = e.Item.Tag as DockWindow;
        if (window != null && window.DockState == DockState.Floating)
        {
            window.CloseAction = DockWindowCloseAction.Hide;
        }
    }
 
    private void button1_Click(object sender, EventArgs e)
    {
        DockWindow[] hiddenWindows = this.radDock1.DockWindows.GetWindows(DockState.Hidden);
        foreach (DockWindow dw in hiddenWindows)
        {
            dw.CloseAction = DockWindowCloseAction.CloseAndDispose;
            dw.Show();
        }
    }
}

I am also attaching a short video showing the result on my end.

I hope this information was useful. Let me know if you have other questions.

Regards,
Hristo
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
Dock
Asked by
Nicholas
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Share this question
or