隐藏/拦截在C#中使用Windows窗体标签 [英] Hiding/blocking tabs using windows forms in c#

查看:151
本文介绍了隐藏/拦截在C#中使用Windows窗体标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的事情是,我有一个登录窗口,并且被按压在日志中按钮或贵宾按钮

The thing is that i have a 'log in window' and a 'mainwindow' that is called after pressing the log in button or the "VISITANT" button

如果按登录按钮,整个系统就会出来,如果我按贵宾按钮,一个标签就会消失或者被阻塞或东西。

If pressing the log in button, the whole system will come out, and if i press the VISITANT button, one tab should disappear or be blocked or something.

private void visitant(object sender, EventArgs e)
{
        mainwindow menu = new mainwindow();
        menu.Show();

        //mainwindow.tabPage1.Enabled = false; //attempt1
        //mainwindow.tabPage1.Visible = false; //attempt1

        //System.Windows.Forms.tabPage1.Enabled = false;//attempt2
        //System.Windows.Forms.tabPage1.Visible = false;//attempt2

        this.Hide();
}



错误我得到了使用attempt1是

the errors i get for using the attempt1 are

错误1'System.mainwindow.tabPage1'不可访问由于其保护水平的对象引用是所必需的非静态字段,方法或特性结果,
错误2 System.mainwindow.tabPage1

Error 1 'System.mainwindow.tabPage1' is inaccessible due to its protection level'
Error 2 An object reference is required for the non-static field, method, or property 'System.mainwindow.tabPage1'

和一个我得到了使用ATTEMPT2是

and the one i get for using the attempt2 is

错误1类型或命名空间名称tabPage1'不命名空间中存在'System.Windows.Forms的(是否缺少程序集引用?)

Error 1 The type or namespace name 'tabPage1' does not exist in the namespace 'System.Windows.Forms' (are you missing an assembly reference?)

正如你可能已经猜到 tabPage1是我需要按贵宾按钮时隐藏标签。

as you probably have guessed "tabPage1" is the tab i need to hide when pressing the visitant button.

我想不出任何更多的细节,我将围绕提供任何额外的信息

I can't think of any more details, I will be around to provide any extra information

在此先感谢。

推荐答案

控件添加到您的窗体在默认情况下,不公开可见。你的attempt1的代码是正确的代码,除了这个细节

The controls you add to your form are, by default, not publicly visible. Your "attempt1" code would be the correct code, except for this detail.

编辑:以这种方式解决它,改变修饰符 tabPage1 的属性为公开内部 - 这使得其他课程,看看从形式之外的控制。)

( to fix it this way, change the "Modifiers" property of tabPage1 to be Public or Internal - this allows other classes to see those controls from outside the form.)

不过,不是让这些控件可见一个更好的方法是在创建一个新的公共方法,您的主窗口类,像这样:

However, a better approach than making these controls visible would be to create a new public method on your mainwindow class, something like this:

public void HideTab()
{
   tabPage1.Enabled = false;
   tabPage1.Visible = false;
}



然后,在你的示例代码,请致电新方法在创建后/节目形式:

Then, in your sample code, call your new method after you create/show the form:

 mainwindow menu = new mainwindow();
 menu.Show();
 menu.HideTab();

这篇关于隐藏/拦截在C#中使用Windows窗体标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆