【问题标题】:How to add a context menu to a supertabControl如何将上下文菜单添加到 supertabControl
【发布时间】:2016-04-07 14:41:39
【问题描述】:

我正在使用DotNetBar 组件SuperTabControl,如果用户右键单击选项卡,我想显示上下文菜单,我找到了以下代码,但问题是我的SuperTabControl 没有 GetTabRect功能。

if (e.Button == MouseButtons.Right)
            {
                for (int i = 0; i < this.superTabControl1.Tabs.Count; ++i)
                {
                    Rectangle r = this.superTabControl1.GetTabRect(i);
                    if (r.Contains(e.Location))
                    {
                       //display menu 
                    }
                }
            } 

【问题讨论】:

  • 听起来像是 DevComponents 的问题。
  • 也许吧,但我想我们可以在这里问任何问题:)
  • 我的意思是你会在那里得到更好的答案。他们做到了。在这里,您必须希望遇到有经验的用户。但是,无论如何......
  • 我明白你的意思,你是完全正确的,但我需要在短时间内得到答案,所以我必须使用任何可能的方式来得到它,谢谢你的建议它真的很有帮助。
  • this.superTabControl1.Tabs[0].Bounds这样的属性吗?因为你只是在寻找一个命中框。

标签: c# winforms visual-studio dotnetbar


【解决方案1】:

只要我的问题没有答案,我就使用此代码根据上下文菜单上的选定选项管理关闭选项卡。 要关闭除已选择的选项卡以外的所有选项卡,我使用了此代码。

for (int i = this.superTabControl1.Tabs.Count - 1; i >= 0; i--)
            {
                BaseItem item = this.superTabControl1.Tabs[i];
                if (!item.Equals(this.superTabControl1.SelectedTab))
                {
                    (item as SuperTabItem).Close();
                }
            }

关闭所有选项卡。

 for (int i = this.superTabControl1.Tabs.Count - 1; i > 0; i--)
            {
                BaseItem item = this.superTabControl1.Tabs[i];
                (item as SuperTabItem).Close();
            }

要关闭选定的选项卡,我使用了以下代码:

this.superTabControl1.SelectedTab.Close();

【讨论】:

    猜你喜欢
    • 2010-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 1970-01-01
    • 2017-06-29
    相关资源
    最近更新 更多