本文介绍了WinForm的MenuStrip中和隐藏标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我想创建其中的TabPages将在MenuStrip中的点击过滤一个TabControl的。

Hello I'm thinking of creating a tabcontrol which the tabpages will be filtered by the clicks in the menustrip.

有关前。

我的MenuStrip在形式上1
和我的TabControl在形式上2

My menustrip is in form 1and my tabcontrol is in form 2

我的tabcontrol由7片,我想只有1个选项卡将在同一时间显示。

My tabcontrol consist of 7 tabs and I want only 1 tab will be shown at a time.

例如如果我在MenuStrip中单击名称它会打开/呈现新的形式和在的TabControl将只显示名称选项卡。

for example If I click the name in the menustrip it will open/show a new form and the tabcontrol will only show the names tab.

我不知道它的可能的,因为决策差异的形式为每个列表似乎是很长的。

I wonder if its possible because making diff forms for each list seems to be very long.

感谢阅读这一点。

推荐答案

但问题是,在 TabPage的控件没有可见属性(当然,它有,但不起任何作用)。所以,你不能隐藏和显示选项​​卡。 。你必须删除应该是不可见的标签

Problem is, the TabPage control has no Visible property (well, it has, but it does nothing). So you can't hide and show tabs at will. You'll have to remove the tabs that should not be visible.

您可以做一个表单(名为TabbedForm)使用如下代码:

You could make a form (named TabbedForm) with code like this:

private readonly int _index;

public TabbedForm(int index)
{
  this._index = index;
  InitializeComponent();
}

private void form_Load(object sender, EventArgs e)
{
  for (int index = this.tabControl1.TabPages.Count - 1; index >= 0; index--)
  {
    if (index != this._index)
      this.tabControl1.TabPages.Remove(this.tabControl1.TabPages[index]);
  }
}

通过每个菜单按钮(单击的事件),在主窗体可以打开使用不同的指数TabbedForm。

With each menu button (Clicked event) in your main form you can open a TabbedForm with a different index.

这篇关于WinForm的MenuStrip中和隐藏标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-16 06:57