problems with panals
-
I have a problem. On my form (mainform) is use a panal wich should load another form (form1) now i placed the panal en he should load the form1 when the mainform loads. but i get this error: Top-level control cannot be added to a control. i don't know what to do whit this error.
public partial class main : Form { Form1 from1; public main() { InitializeComponent(); } internal Form1 From1 { get { if (this.from1 == null) { this.from1 = new Form1(); this.panel1.Controls.Add(this.from1); this.from1.Dock = DockStyle.Fill; } return this.from1; } } private void main_Load(System.Object sender, System.EventArgs e) { this.FFrom1(); } internal void FFrom1() { this.From1.Visible = true; }
this is my code i use visual C# 2005 and offcourse writing in C# can anyone help me? -
I have a problem. On my form (mainform) is use a panal wich should load another form (form1) now i placed the panal en he should load the form1 when the mainform loads. but i get this error: Top-level control cannot be added to a control. i don't know what to do whit this error.
public partial class main : Form { Form1 from1; public main() { InitializeComponent(); } internal Form1 From1 { get { if (this.from1 == null) { this.from1 = new Form1(); this.panel1.Controls.Add(this.from1); this.from1.Dock = DockStyle.Fill; } return this.from1; } } private void main_Load(System.Object sender, System.EventArgs e) { this.FFrom1(); } internal void FFrom1() { this.From1.Visible = true; }
this is my code i use visual C# 2005 and offcourse writing in C# can anyone help me?Set the
TopLevel
property of yourForm
tofalse
prior to adding it. -
Set the
TopLevel
property of yourForm
tofalse
prior to adding it.thanks for your fast reply where acactly should i'de be doing that. on the Mainform (the form with the panal) or Form1 (the form that's load) toplevel = false; or something like that was the code but where should i put this. before the panal loads or somewhere else?
-
thanks for your fast reply where acactly should i'de be doing that. on the Mainform (the form with the panal) or Form1 (the form that's load) toplevel = false; or something like that was the code but where should i put this. before the panal loads or somewhere else?
In the getter of Form1 right before adding it to the Panel:
internal Form1 From1
{
get
{
if (this.from1 == null)
{
this.from1 = new Form1();this.from1.TopLevel = false; //HERE!!!! this.panel1.Controls.Add(this.from1); this.from1.Dock = DockStyle.Fill; } return this.from1;
}
} -
In the getter of Form1 right before adding it to the Panel:
internal Form1 From1
{
get
{
if (this.from1 == null)
{
this.from1 = new Form1();this.from1.TopLevel = false; //HERE!!!! this.panel1.Controls.Add(this.from1); this.from1.Dock = DockStyle.Fill; } return this.from1;
}
}oh great that works but can you give one last advise? now if i select a row or something he opens a new form but this he opens outside the panal? how can i do this?
-
oh great that works but can you give one last advise? now if i select a row or something he opens a new form but this he opens outside the panal? how can i do this?
Hi, sorry but I don't understand your question. What rows are you referring to? If you wish to show a
Form
normally just leaveTopLevel
to true and call eitherShow
orShowDialog
on it. -
Hi, sorry but I don't understand your question. What rows are you referring to? If you wish to show a
Form
normally just leaveTopLevel
to true and call eitherShow
orShowDialog
on it.inside the Form1 there is for example a data grid.. with a selectrow command he opens another form with the details of the selected row. this form should be opend inside the panal also
-
inside the Form1 there is for example a data grid.. with a selectrow command he opens another form with the details of the selected row. this form should be opend inside the panal also
First of all you should consider creating user controls instead of forms all the time. Then its the same procedure with any form you have. Set TopLevel to false and then you can insert it into any panel you like. If you want to exchange the contents of a panel then call panel.Controls.Clear() prior to adding the other form. If you want to have several items in one panel you can either set them location and size programmatically or (better) just create two panels (one holding formA and one holding formB).