How to catch a Docking Window Close event

Good day,
I am using the Docking Manager control for my application to display multiple Forms at the same time.
The Forms themselves are set with FormBorderStyle=None for look & feel so only the Docking 'Panel' is visible.

But I need to do some processing whenever a user closes a 'form/window'.
I cannot use the WindowsForms' Closing or Closed events as they are not triggered.

So how do I catch the 'close event' that the X in the green circle's will trigger?


Regards,
James

7 Replies

MK Mallika Kannan Syncfusion Team January 24, 2018 08:32 AM UTC

Hi James  
  
Thank you for contacting Syncfusion support.  
  
We have checked your requirement “Event to notify Dock window closing” and it can be achieved through click event of CaptionButtons. We have prepared sample which tries to meet your requirement and it can be downloaded from below link.    
  
  
Please refer the below Code example.  
  
Code Example: [C#]  
  
//Handle Close Button event 
                                     
this.dockingManager1.CaptionButtons[0].Click += Form1_Click; 
 
private void Form1_Click(object sender, CancelEventArgs e) 
{  
                     //Click Close Button in DockingManager, it shows the below message 
                   MessageBox.Show("Selected Form will Close"); 
} 
 
This below documentation will guide in requested use case.  
  
  
Please get back to us with more details if the provided sample doesn’t meet your requirement.   
  
Regards,  
Mallika 



JR James Roodt January 25, 2018 01:31 PM UTC

Hi Mallika,

Thank you for your response.
Currently I was using DockingManager_DockVisibilityChanged which unfortunately also triggers when the window is hidden.

BUT I have one problem. I have no idea to identify the window being closed.
With DockingManager_DockVisibilityChanged I could use the following to get the window Title:

But neither the object sender, nor the CancelEventArgs of the Click event gives me any indication of which window is actually closing.
So how can i know when a window is being closed AND identify it?

Regards,
James


MK Mallika Kannan Syncfusion Team January 26, 2018 04:52 AM UTC

Hi James 
 
Thank you for your update. 
 
Your reported requirement “How to identify the Which DockingWindow is currently closed?” can be achieved using the below code example.  
 
Code Example: [C#] 
 
private void DockingManager1_DockVisibilityChanged(object sender, DockVisibilityChangedEventArgs arg) 
{ 
                     //GetDockVisibility method gives the detail of the docked control visibility 
 
                     if (this.dockingManager1.GetDockVisibility(arg.Control) == false) 
                     { 
                           //DockVisibilityChangedEventArgs instance arg holds the control being changed the visibility 
                           MessageBox.Show(this.dockingManager1.GetDockLabel(arg.Control) + " " + " window is closed."); 
                     } 
} 
 
Screenshot 
 
 
  
We have also prepared the sample for your reference. It can be downloaded from the below link, 
 
 
Please refer the below documentation will guide in requested use case.   
 
 
Kindly check the above solution and let us know if it is helpful. 
 
Regards, 
Mallika 



JR James Roodt January 26, 2018 06:31 AM UTC

Hi Mallika,

I am already using the  DockingManager_DockVisibilityChanged  event. BUT it is also triggered for the [Hide] menu option. This is why I originally requested on how I could catch the 'Close' event. But as I cannot identify which window is being closed it was not working for me.

So in that, according to you, I have to use the DockingManager_DockVisibilityChanged  event to identify the window, how can I remove the [Hide] menu option of the Docking panel to avoid false triggers of the DockingManager_DockVisibilityChanged  event?





Regards,
James




DR Durga Rajan Syncfusion Team January 29, 2018 07:08 AM UTC

Hi James, 

We have checked your requirement “How can I remove the [Hide] menu option of the Docking panel” and prepared sample which tries to meet your requirement. In this sample we have removed the “Hide” menu item from the ContextMenu while opening the ContextMenu of Dock Panels. Please refer the below code example, 

Code Example : 

        private void DockingManager1_DockContextMenu(object sender, DockContextMenuEventArgs arg) 
        { 
            BarItem item = arg.ContextMenu.ParentBarItem.Items[4] as BarItem;             
            if(item != null && item.Text == "&Hide") 
            { 
                arg.ContextMenu.ParentBarItem.Items.Remove(item);                 
            } 
        } 
 
  
Screenshot :  
 
 
 
Also we have attached the sample for the sample, please download it from below location, 


Please get back to us, if the above sample doesn’t meet your requirement. 

Regards, 
Durga S.   



JR James Roodt February 5, 2018 06:59 AM UTC

Hi Durga,

This is perfect. Thank you very much!

Regards,
James


DR Durga Rajan Syncfusion Team February 6, 2018 03:55 AM UTC

Hi James,

Thanks for the update. Please let us know if you need any further assistance on this.

Regards,
Durga S.

Loader.
Up arrow icon