Usercontrol - Loading into SplitContainer

N

NDB Europe

Hi All,

Sorry but my last post has disapared so appoligies for the repost.

I have a project with Main MDI form called frmMain. I have on there a Split
Container. I also have 2 x UserControls called Form1 & Form2.

When my project starts up I would like UserControl Form1 to populate
splitcontainer.panel1 and Usercontrol Form2 to populate
splitcontainer.panel2.

How can I achive this.

I currently have the following code but it gives me a compile error saying:

Error 1 The type or namespace name 'Form1' could not be found (are you
missing a using directive or an assembly reference?) D:\Winform
Development\Test_Code_Project\Forms\frmMain.cs 19 13 Test_Code_Project

Error 2 The type or namespace name 'Form1' could not be found (are you
missing a using directive or an assembly reference?) D:\Winform
Development\Test_Code_Project\Forms\frmMain.cs 19 31 Test_Code_Project

Error 3 The type or namespace name 'Form2' could not be found (are you
missing a using directive or an assembly reference?) D:\Winform
Development\Test_Code_Project\Forms\frmMain.cs 20 13 Test_Code_Project

Error 4 The type or namespace name 'Form2' could not be found (are you
missing a using directive or an assembly reference?) D:\Winform
Development\Test_Code_Project\Forms\frmMain.cs 20 31 Test_Code_Project

I would be greatfull for any Input you could give.

Code Start:
---------------------------------------
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Test_Code_Project
{
public partial class frmMain : Form
{
private int childFormNumber = 0;

public frmMain()
{
InitializeComponent();
Form1 formA = new Form1();
Form2 formB = new Form2();
formA.TopLevel = false;
formB.TopLevel = false;
splitContainer1.Panel1.Controls.Add(formA);
splitContainer1.Panel2.Controls.Add(formB);
formA.Show();
formB.Show();
}

private void ShowNewForm(object sender, EventArgs e)
{
Form childForm = new Form();
childForm.MdiParent = this;
childForm.Text = "Window " + childFormNumber++;
childForm.Show();
}

private void TileVerticalToolStripMenuItem_Click(object sender,
EventArgs e)
{
LayoutMdi(MdiLayout.TileVertical);
}

private void TileHorizontalToolStripMenuItem_Click(object sender,
EventArgs e)
{
LayoutMdi(MdiLayout.TileHorizontal);
}

private void ArrangeIconsToolStripMenuItem_Click(object sender,
EventArgs e)
{
LayoutMdi(MdiLayout.ArrangeIcons);
}

private void CloseAllToolStripMenuItem_Click(object sender,
EventArgs e)
{
foreach (Form childForm in MdiChildren)
{
childForm.Close();
}
}

private void frmMain_Load(object sender, EventArgs e)
{

}

}
}

Many Thanks
Best Regards
Si
 
N

NDB Europe

Hi Them,

Thanks for your reply. Sorry im new to C#.

The From1, Form2 is simply where i have been testing. I will rename them to
more appropriate names once i get to grasps with everything.

What do you mean by "referenced somehow in your project and the type is
appropriately qualified (i.e. by some combination of "using" directive and
namespace/containing class qualifications"?

How would I go about doing that? I`ve searched and search on google and in
the Newsgroups but can't seem to find any examples:(

Many Thanks Again
Si



Peter Duniho said:
[...]
I currently have the following code but it gives me a compile error
saying:

Error 1 The type or namespace name 'Form1' could not be found (are you
missing a using directive or an assembly reference?) D:\Winform
Development\Test_Code_Project\Forms\frmMain.cs 19 13 Test_Code_Project

[...etc...]

I would be greatfull for any Input you could give.

The error messages seem pretty clear to me. Is there something about them
specifically that's confusing you? You can't use a type unless it's
referenced somehow in your project and the type is appropriately qualified
(i.e. by some combination of "using" directive and namespace/containing
class qualifications).

Also, IMHO it's very bad form to name a UserControl sub-class "Form1" or
"Form2".

Pete
 
N

NDB Europe

Hi Them,

Thanks for your reply. Sorry im new to C#.

The From1, Form2 is simply where i have been testing. I will rename them to
more appropriate names once i get to grasps with everything.

What do you mean by "referenced somehow in your project and the type is
appropriately qualified (i.e. by some combination of "using" directive and
namespace/containing class qualifications"?

How would I go about doing that? I`ve searched and search on google and in
the Newsgroups but can't seem to find any examples:(

Many Thanks Again
Si



Peter Duniho said:
[...]
I currently have the following code but it gives me a compile error
saying:

Error 1 The type or namespace name 'Form1' could not be found (are you
missing a using directive or an assembly reference?) D:\Winform
Development\Test_Code_Project\Forms\frmMain.cs 19 13 Test_Code_Project

[...etc...]

I would be greatfull for any Input you could give.

The error messages seem pretty clear to me. Is there something about them
specifically that's confusing you? You can't use a type unless it's
referenced somehow in your project and the type is appropriately qualified
(i.e. by some combination of "using" directive and namespace/containing
class qualifications).

Also, IMHO it's very bad form to name a UserControl sub-class "Form1" or
"Form2".

Pete
 
N

NDB Europe

Hi There,

Thanks again for you prompt response.

Im very confused. They are all part of the same project.

I am using the using System.Windows.Forms; as a namespace at the top of my
project. Should that not work? as the Usercontrol Form is in the same
project?

Could you point me in the direction of some code or suggest what i need to
add code wise? I`ve just read the link but

Cheers Again
Si
 
N

NDB Europe

Hi There,

Thanks again for you prompt response.

Im very confused. They are all part of the same project.

I am using the using System.Windows.Forms; as a namespace at the top of my
project. Should that not work? as the Usercontrol Form is in the same
project?

Could you point me in the direction of some code or suggest what i need to
add code wise? I`ve just read the link but

Cheers Again
Si
 
N

NDB Europe

Hi There,

Thanks again for you reply. In my Main form the code is:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VOIP_Master_Biller
{
public partial class frmMain : Form
{
private int childFormNumber = 0;

public frmMain()
{
InitializeComponent();
Form1 formA = new Form1();
Form2 formB = new Form2();
formA.TopLevel = false;
formB.TopLevel = false;
splitContainer1.Panel1.Controls.Add(formA);
splitContainer1.Panel2.Controls.Add(formB);
formA.Show();
formB.Show();
}

private void ShowNewForm(object sender, EventArgs e)
{
Form childForm = new Form();
childForm.MdiParent = this;
childForm.Text = "Window " + childFormNumber++;
childForm.Show();
}

private void TileVerticalToolStripMenuItem_Click(object sender,
EventArgs e)
{
LayoutMdi(MdiLayout.TileVertical);
}

private void TileHorizontalToolStripMenuItem_Click(object sender,
EventArgs e)
{
LayoutMdi(MdiLayout.TileHorizontal);
}

private void ArrangeIconsToolStripMenuItem_Click(object sender,
EventArgs e)
{
LayoutMdi(MdiLayout.ArrangeIcons);
}

private void CloseAllToolStripMenuItem_Click(object sender,
EventArgs e)
{
foreach (Form childForm in MdiChildren)
{
childForm.Close();
}
}

private void frmMain_Load(object sender, EventArgs e)
{

}

}
}

Then I have a user control called Form1 with the following code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VOIP_Master_Biller.Forms
{
public partial class Form1 : UserControl
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}
}
}

Both Forms have the using system.windows.forms at the top.

Cheers
Si
 
N

NDB Europe

Hi There,

Thanks again for you reply. In my Main form the code is:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VOIP_Master_Biller
{
public partial class frmMain : Form
{
private int childFormNumber = 0;

public frmMain()
{
InitializeComponent();
Form1 formA = new Form1();
Form2 formB = new Form2();
formA.TopLevel = false;
formB.TopLevel = false;
splitContainer1.Panel1.Controls.Add(formA);
splitContainer1.Panel2.Controls.Add(formB);
formA.Show();
formB.Show();
}

private void ShowNewForm(object sender, EventArgs e)
{
Form childForm = new Form();
childForm.MdiParent = this;
childForm.Text = "Window " + childFormNumber++;
childForm.Show();
}

private void TileVerticalToolStripMenuItem_Click(object sender,
EventArgs e)
{
LayoutMdi(MdiLayout.TileVertical);
}

private void TileHorizontalToolStripMenuItem_Click(object sender,
EventArgs e)
{
LayoutMdi(MdiLayout.TileHorizontal);
}

private void ArrangeIconsToolStripMenuItem_Click(object sender,
EventArgs e)
{
LayoutMdi(MdiLayout.ArrangeIcons);
}

private void CloseAllToolStripMenuItem_Click(object sender,
EventArgs e)
{
foreach (Form childForm in MdiChildren)
{
childForm.Close();
}
}

private void frmMain_Load(object sender, EventArgs e)
{

}

}
}

Then I have a user control called Form1 with the following code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace VOIP_Master_Biller.Forms
{
public partial class Form1 : UserControl
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

}
}
}

Both Forms have the using system.windows.forms at the top.

Cheers
Si
 
N

NDB Europe

Hi Peter,

You are a Genius,

Adding VOIP_Master_Biller.Forms.Form2 worked like a treat.

I didnt quite understand what you mean by "bringing your UserControl
sub-classes into the "VOIP_Master_Biller" namespace, simply by changing the
namespace declaration around the class declarations for "Form1" and
"Form2".

Sorry im still a stupid newbie:(

However many many thanks for the advice. It is much appriciated.

Best Regards
Si
classes into their own namespace.

Peter Duniho said:
[...]
namespace VOIP_Master_Biller
{
public partial class frmMain : Form
{
private int childFormNumber = 0;

public frmMain()
{
InitializeComponent();
Form1 formA = new Form1();
Form2 formB = new Form2();
formA.TopLevel = false;
formB.TopLevel = false;
splitContainer1.Panel1.Controls.Add(formA);
splitContainer1.Panel2.Controls.Add(formB);
formA.Show();
formB.Show();
}

[...]
}
}

[...]
namespace VOIP_Master_Biller.Forms
{
public partial class Form1 : UserControl
{
[...]
}
}

Both Forms have the using system.windows.forms at the top.

As I said, the namespace System.Windows.Forms has nothing to do with your
problem.

From the code you posted, assuming the source files are in the same
project, all you should have to do to fix the error is one of two things:

-- add "using VOIP_Master_Biller.Forms;" to the top of the main form
source file

-- use the class names "VOIP_Master_Biller.Forms.Form1" and
"VOIP_Master_Biller.Forms.Form2" instead of simply "Form1" and "Form2",
respectively.

Either technique will fix the error.

Of course, you could also fix the error by bringing your UserControl
sub-classes into the "VOIP_Master_Biller" namespace, simply by changing
the namespace declaration around the class declarations for "Form1" and
"Form2". But presumably you have a specific reason for putting those
classes into their own namespace.

Pete
 
N

NDB Europe

Hi Peter,

You are a Genius,

Adding VOIP_Master_Biller.Forms.Form2 worked like a treat.

I didnt quite understand what you mean by "bringing your UserControl
sub-classes into the "VOIP_Master_Biller" namespace, simply by changing the
namespace declaration around the class declarations for "Form1" and
"Form2".

Sorry im still a stupid newbie:(

However many many thanks for the advice. It is much appriciated.

Best Regards
Si
classes into their own namespace.

Peter Duniho said:
[...]
namespace VOIP_Master_Biller
{
public partial class frmMain : Form
{
private int childFormNumber = 0;

public frmMain()
{
InitializeComponent();
Form1 formA = new Form1();
Form2 formB = new Form2();
formA.TopLevel = false;
formB.TopLevel = false;
splitContainer1.Panel1.Controls.Add(formA);
splitContainer1.Panel2.Controls.Add(formB);
formA.Show();
formB.Show();
}

[...]
}
}

[...]
namespace VOIP_Master_Biller.Forms
{
public partial class Form1 : UserControl
{
[...]
}
}

Both Forms have the using system.windows.forms at the top.

As I said, the namespace System.Windows.Forms has nothing to do with your
problem.

From the code you posted, assuming the source files are in the same
project, all you should have to do to fix the error is one of two things:

-- add "using VOIP_Master_Biller.Forms;" to the top of the main form
source file

-- use the class names "VOIP_Master_Biller.Forms.Form1" and
"VOIP_Master_Biller.Forms.Form2" instead of simply "Form1" and "Form2",
respectively.

Either technique will fix the error.

Of course, you could also fix the error by bringing your UserControl
sub-classes into the "VOIP_Master_Biller" namespace, simply by changing
the namespace declaration around the class declarations for "Form1" and
"Form2". But presumably you have a specific reason for putting those
classes into their own namespace.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top