C# Tab Control Empty Space Double Click

本秂侑毒 提交于 2020-02-21 06:08:18

问题


I am writing a C# WinForm application. I have a Tab Control and I've already preset all functions such as adding new tabs by menu, and double clicking tabs to delete. My issue now is I want to create a tab every time I double click the empty grey space of the tab control.

I've been searching for about an hour now and a lot of what I find is dealing with WPF and I'd rather not delve into those anytime soon. So I'm looking for a matter to fit my means of detecting the double click. I've tried double click and mouse double click double click works on tabs, and mouse double click does the same except it captures the mouse event arguments. So then I'm able to use

e.Location

Except it only provides that information on the tabs themselves. Anyone have any suggestions to capture that double click outside the tabs themselves? I've tried go up in parents such as mouse double click on the window itself, tried creating a completely opaque element that may handle the clicks instead but I've hit a brick wall every time.

 private void Tabs_MouseDoubleClick(object sender, MouseEventArgs e)
 {
      //only works when double clicking tabs
      MessageBox.Show(e.Location.ToString());
 }

回答1:


It seems that part of TabControl is transparent to mouse and all mouse events pass through the part and will be received by the control which is behind the part.

So as a workaround you can put the TabControl in a Panel and set the Dock property of TabControl to Fill, and the handle DoubleClick event of Panel. You also have the option of mouse hooks, but I believe the panel option is simpler.

Mouse-trasparent part of control is shown in red color in below image. Also borders of control are part of that area.



来源:https://stackoverflow.com/questions/39321551/c-sharp-tab-control-empty-space-double-click

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!