Customizing a TabControl for the Closing of Individual Tabs

前端 未结 7 1291
囚心锁ツ
囚心锁ツ 2020-12-06 10:33

My scenario is the following:

I am working on a winforms application in C# that has a button inside the main page of a tabcontrol that will generate another tabpag

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-06 10:54

    This code might help throgh closing the tab controls with middle mouse click :

                private void tabControl1_MouseDown(object sender, MouseEventArgs e)
                {
                    if (e.Button != System.Windows.Forms.MouseButtons.Middle)
                        return;
    
                    for (int i = 0; i < MainTabControl.TabPages.Count; i++)
                    {
                        if (this.MainTabControl.GetTabRect(i).Contains(e.Location))
                        {
                            this.MainTabControl.TabPages.RemoveAt(i);
                            return;
                        }
                    }
                }
    

提交回复
热议问题