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

标签 c# winforms tabpage

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

最佳答案

实现 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;
                }
            }
        }
    }

关于c# - 右键单击时如何聚焦某个标签页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3552508/

相关文章:

c# - 如何在 ASP.NET Core 健康检查中注入(inject)依赖项

c# - 从 byte[] 中找出图像的 ContentType

c# - 使用 C# WinForms 应用程序访问另一个应用程序的元素

c# - 如何处理同一控件上的快捷键和按住键

c# - 如何在 C# 中隐藏/阻止选项卡?

c# - 自动生成的 RDLC 代码不考虑子报表中的分页符

c# - 使用连接选择多个表中的多个项目

c# - 在 Windows 7 下创建新文件和目录时,我的代码会导致崩溃吗?

c# - 如何使 Tab 页面的宽度适合 TabControl 的宽度

C# Winforms TabControl 元素读取为空,直到选择 TabPage