Customizing a TabControl for the Closing of Individual Tabs

前端 未结 7 1335
囚心锁ツ
囚心锁ツ 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:45

    I found this code and was very helpful to me:

    private void tabControl_MouseUp(object sender, MouseEventArgs e)
    {
        // check if the right mouse button was pressed
        if(e.Button == MouseButtons.Right)
        {
            // iterate through all the tab pages
            for(int i = 0; i < tabControl1.TabCount; i++)
            {
                // get their rectangle area and check if it contains the mouse cursor
                Rectangle r = tabControl1.GetTabRect(i);
                if (r.Contains(e.Location))
                {
                    // show the context menu here
                    System.Diagnostics.Debug.WriteLine("TabPressed: " + i);
                 }
            }
        }
    }
    

    TabControl: How To Capture Mouse Right-Click On Tab

提交回复
热议问题