Posted 22 May 2019, 4:44 pm EST
Hello,
When we tear off a page from a dockingtab, a new DockingTab is created and added to C1CommandDock’s Control collection. Then the teared off is removed from parent DockingTab’s TabPages collection and added to the new DockingTab’s TabPages collection.
To take care of such scenario, you should handle C1CommandDock’s ControlAdded event and inside add a handler to its MouseClick event as follows:
private void Form1_Load(object sender, EventArgs e)
{
c1CommandDock1.ControlAdded += C1CommandDock1_ControlAdded;
}
private void C1CommandDock1_ControlAdded(object sender, ControlEventArgs e)
{
if(e.Control.GetType()==typeof(C1.Win.C1Command.C1DockingTab))
{
var newTab = e.Control as C1.Win.C1Command.C1DockingTab;
if(newTab.HasChildren)
{
newTab.MouseClick += c1DockingTab1_MouseClick;
}
}
}
private void c1DockingTab1_MouseClick(object sender, MouseEventArgs e)
{
var dockTab = sender as C1.Win.C1Command.C1DockingTab;
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
for (int pg = 0; pg < dockTab.TabPages.Count; pg++)
{
if (dockTab.TabPages[pg].TabBounds.Contains(e.Location) == true)
{
System.Diagnostics.Debug.WriteLine($"DockingTabPage clicked: {dockTab.TabPages[pg].Name}");
}
}
}
}
```Also, I've modified the application and attached here for your reference.
Let me know, if you find any other scenarios where you want to detect tab click to work.
Best Regards,
Ruchir
[zip filename="TabClick_TabPageModified.zip"]https://gccontent.blob.core.windows.net/forum-uploads/file-3fb95be0-8c73-4600-b5be-9425ad9375a1.zip[/zip]