简体   繁体   English

Winform菜单栏和隐藏选项卡

[英]Winform menustrip and hiding tabs

Hello I'm thinking of creating a tabcontrol which the tabpages will be filtered by the clicks in the menustrip. 您好,我在考虑创建一个tabcontrol,通过单击菜单条中的单击可以过滤这些tabpage。

For ex. 对于前。

My menustrip is in form 1 and my tabcontrol is in form 2 我的菜单栏处于表格1中,而tabcontrol处于表格2中

My tabcontrol consist of 7 tabs and I want only 1 tab will be shown at a time. 我的tabcontrol由7个标签组成,我希望一次只显示1个标签。

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. 例如,如果我单击菜单栏中的名称,它将打开/显示一个新表单,而tab控件将仅显示“名称”标签。

I wonder if its possible because making diff forms for each list seems to be very long. 我不知道是否可能,因为为每个列表制作差异表格似乎很长。

thanks for reading this. 感谢您阅读本文。

Problem is, the TabPage control has no Visible property (well, it has, but it does nothing). 问题是, TabPage控件没有Visible属性(虽然它具有Visible属性,但是它什么也不做)。 So you can't hide and show tabs at will. 因此,您无法随意隐藏和显示标签。 You'll have to remove the tabs that should not be visible. 您必须删除不可见的标签。

You could make a form (named TabbedForm) with code like this: 您可以使用以下代码制作一个表单(名为TabbedForm):

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]);
  }
}

With each menu button ( Clicked event) in your main form you can open a TabbedForm with a different index. 使用主窗体中的每个菜单按钮( Clicked事件),您可以打开一个具有不同索引的TabbedForm。

Yes, this will work pretty fine. 是的,这可以正常工作。 But I think, you must use the default tab view control for this and that must not create the problem either in you case too. 但是我认为,您必须为此使用默认的选项卡视图控件,并且在任何情况下也都不会造成问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM