Articles in this section
Category / Section

How to detect if FloatingWindow close button is clicked?

1 min read

Close button of Floating window clicked event can detected from the VisibleChanged event of FloatingForm. Here we get the FloatingForm on DockStateChanged event. VisibleChanged event of FloatingForm will be raised when we click the close button. The following code demonstrates the same.

 

C#

//Initialize the Panels
 
this.panel1 = new System.Windows.Forms.Panel();
 
this.panel2 = new System.Windows.Forms.Panel();
 
this.panel3 = new System.Windows.Forms.Panel();
 
//Docking VisualStyle
 
this.dockingManager1.VisualStyle = VisualStyle.Metro;
 
//For Docking Panels
 
this.dockingManager1.SetDockLabel(this.panel1, "panel1");
 
this.dockingManager1.SetEnableDocking(this.panel1, true);
 
this.dockingManager1.SetDockLabel(this.panel2, "panel2");
 
this.dockingManager1.SetEnableDocking(this.panel2, true);
 
this.dockingManager1.SetDockLabel(this.panel3, "panel");
 
this.dockingManager1.SetEnableDocking(this.panel3, true);
 
//For Getting Floating Form
this.dockingManager1.DockStateChanged += dockingManager1_DockStateChanged;
 
void dockingManager1_DockStateChanged(object sender, Syncfusion.Windows.Forms.Tools.DockStateChangeEventArgs arg)
{
 
if (this.dockingManager1.IsFloating(arg.Controls[0]))
{
 
if (arg.Controls[0].TopLevelControl != null && arg.Controls[0].TopLevelControl is FloatingForm)
 
//For Close Button clicked on Floating Form
 
(arg.Controls[0].TopLevelControl as FloatingForm).VisibleChanged += Form1_VisibleChanged;
 
}
}
 
bool CloseButtonClicked=false;
 
void Form1_VisibleChanged(object sender, EventArgs e)
{
 
CloseButtonClicked = true;
 
MessageBox.Show("CloseButtonClicked");
 
}

 

VB

'Initialize the Panels
 
Me.panel1 = New System.Windows.Forms.Panel()
 
Me.panel2 = New System.Windows.Forms.Panel()
 
Me.panel3 = New System.Windows.Forms.Panel()
 
'Docking VisualStyle
 
Me.dockingManager1.VisualStyle = VisualStyle.Metro
 
'For Docking Panels
 
Me.dockingManager1.SetDockLabel(Me.panel1, "panel1")
 
Me.dockingManager1.SetEnableDocking(Me.panel1, True)
 
Me.dockingManager1.SetDockLabel(Me.panel2, "panel2")
 
Me.dockingManager1.SetEnableDocking(Me.panel2, True)
 
Me.dockingManager1.SetDockLabel(Me.panel3, "panel")
 
Me.dockingManager1.SetEnableDocking(Me.panel3, True)
 
'For Getting Floating Form
AddHandler Me.dockingManager1.DockStateChanged, AddressOf dockingManager1_DockStateChanged
 
void dockingManager1_DockStateChanged(Object sender, Syncfusion.Windows.Forms.Tools.DockStateChangeEventArgs arg)
If True Then
 
If Me.dockingManager1.IsFloating(arg.Controls(0)) Then
 
If arg.Controls(0).TopLevelControl IsNot Nothing AndAlso TypeOf arg.Controls(0).TopLevelControl Is FloatingForm Then
 
'For Close Button clicked on Floating Form
 
AddHandler TryCast(arg.Controls(0).TopLevelControl, FloatingForm).VisibleChanged, AddressOf Form1_VisibleChanged
End If
 
End If
End If
 
Dim CloseButtonClicked As Boolean=False
 
void Form1_VisibleChanged(Object sender, EventArgs e)
If True Then
 
CloseButtonClicked = True
 
MessageBox.Show("CloseButtonClicked")
 
End If
 

 

 

Screenshot

 

 

Showing close button is clicked

Samples:

 

C#: DockingManagerSample

 

VB: DockingManagerSample

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied