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();
}
the errors i get for using the attempt1 are
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'
and the one i get for using the attempt2 is
Error 1 The type or namespace name 'tabPage1' does not exist in the namespace 'System.Windows.Forms' (are you missing an assembly reference?)
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
Thanks in advance.
Assuming you are using a System.Windows.Forms.TabControl for your tabPages called tabControl1, use the following:
If you want to view the tabPage1 again, use:
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.
(EDIT: to fix it this way, change the "Modifiers" property of
tabPage1
to bePublic
orInternal
- 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:Then, in your sample code, call your new method after you create/show the form:
you need to expose the tab control by declaring a public property. Then you can access it using
menu
which is you instance.Better option is that you Expose a property in mainwindow like
and then set it to true or false by
finally apply the logic in load event of the mainwindow form.