I'll start with this: I'm no good at C#. I don't for the most part know what I'm doing.
Now the disclaimer is out the way, I'm trying to access a TabControl in my Interface (made using VS2008, so parts are in Interface.Designer) from another class - except using Interface.tabControl1
tells me i need an object reference, and if I type .
after Interface
I just get a list of stuff, not any of the objects within the interface. Using Interface.ControlCollection
doesn't help either.
Help is appreciated, and I'm sure this is really basic and I'm just a spanner, but oh well.
EDIT: in Program.cs
(which i would guess was autocreated when I started building the app), the interface is created nameless:
static void Main()
{
Application.Run(new Interface());
}
Interface()
is called from Interface.cs
:
public partial class Interface : Form
{
public Interface()
{
InitializeComponent();
}
}
The rest of the partial class is created in Interface.Designer.cs
- which was autogenerated when I was building the interface in the VS2008 designer.
I'm not sure if that helps, or is of no use. But there it is anyway. =)
EDIT #2:
I think i should explain what I'm doing, maybe then people will understand what I need out of this:
I had an interface, with a tabcontrol, and tabs generated on-the-fly based on whatever the user was doing. This was causing problems because i wasn't making each tab its own object, so when it came to accessing stuff in the pages without affecting other tabs, it didn;t work. As such, i removed all the code from a method in Interface.cs
that was used to build a tab, and made a new class called Tab.cs
- This is where the problem of broken references appeared. Relevant code, moved from Interface into Tab:
public Tab(string inputstring)
{
.....
//call this method if button is clicked
cancel.Click += new System.EventHandler(this.close_Click);
//ridiculous calculations to get the buttons in the right place
int leftside = ((tabControl1.Width / 100) * 96);
int bottomside = ((tabControl1.Height / 100) * 93);
int bottomside2 = ((tabControl1.Height / 100) * 99);
.....
//call this method if button is clicked
save.Click += new System.EventHandler(this.save_Click);
.....
//call this method when tab is entered
newtab.Enter += new System.EventHandler(this.tabSelect);
}
Of particular relevance is the code with tabControl1.Width. This then leads back to what I started trying to ask about before.
I hope that maybe makes things clearer.
EDIT3: (for Henk Holterman) I've renamed Interface to MainForm. VS2008 decided it should be called interface, I simply didn't change that. But I see why change is good, thank you =P