右键单击时如何聚焦某个标签页?

时间:2010-08-23 23:38:06

标签: c# winforms tabpage

如何在右键单击时选择或聚焦某个标签页?

1 个答案:

答案 0 :(得分:1)

实施MouseDown事件并找出点击了哪个标签:

    private void tabControl1_MouseDown(object sender, MouseEventArgs e) {
        if (e.Button == MouseButtons.Right) {
            for (int tab = 0; tab < tabControl1.TabCount; ++tab) {
                if (tabControl1.GetTabRect(tab).Contains(e.Location)) {
                    tabControl1.SelectedIndex = tab;
                    break;
                }
            }
        }
    }