I have been working on project for the past one month but I am really stucked. I have a form called MainForm which has 2 panels. One is called MainContainer and other called SubContainer. I have two other forms, one called Login and other SQLSettings. SubContainer is found inside MainContainer. SubContainer is suppose to hold all open forms. When MainForm loads at startup it opens Login form inside SubContainer. Login contains a linklabel which is also suppose to open SQLSettings form in SubContainer but nothing happens when i click on the linklabel in the Login form.
What I have tried:
this is the code for the linklabel which is suppose to open SQLSettings form:
this.Close();
MainForm f = new MainForm();
Form cur = new SQLSettings();
f.SubContainer.Dock = DockStyle.None;
f.SubContainer.Anchor = AnchorStyles.None;
f.SubContainer.Size = cur.Size;
f.SubContainer.Location = new Point(f.MainContainer.Width / 2 - f.SubContainer.Width / 2,
f.MainContainer.Height / 2 - f.SubContainer.Height / 2);
cur.TopLevel = false;
f.SubContainer.Controls.Remove(f.currentForm);
f.SubContainer.Tag = cur;
f.SubContainer.Controls.Add(cur);
f.SubContainer.Tag = cur;
cur.BringToFront();
cur.Show();
Child form can be opened inside the parent form with setting property MdiParent.
According to your MainForm as parent and SQLSettings form as child:
MainForm f = new MainForm();
Form cur = new SQLSettings();
cur.MdiParent = f;
cur.BringToFront();
cur.Show();
Related
i am new in c# windows application learning
i have 3 form.
main form, form menu, child form
in main form when i click on button1, form menu is show in 1st panel.
this code in main form.....this work properly for me... if anyone have better then this then suggest me.
private void button1_Click(object sender, EventArgs e)
{
bool IsOpen = false;
foreach (Form frmchild in Application.OpenForms)
{
if (frmchild.Text == "Child Form")
{
IsOpen = true;
frmchild.Close();
break;
}
}
if (IsOpen == false)
{
child form cf = new child form();
cf.Owner = this; //main form is owenr
cf.Show();
cf.Location
= new Point(button1.Left + 37, button1.Height + button1.Top + 4);
}
}
main form have 2 panel, 1st is small and dock in top. 2nd is main panel (dock = fill) where i want to dock all child form.
in form menu i have button and when i click on i want to open child form in main form 2nd panel.
please help me to open child form in main form's panel when i click button in another child form in c# language.
please help me.
i think you have to use USER CONTROL instead of a form. Add a usercontrol at your prject and here is the code :
for (int i = panel2.Controls.Count; i > 0; i--)
{
panel2.Controls[i-1].Dispose();
}
//add user control you want
UserControl1 uc = new UserControl1();
panel2.Controls.Add(uc);
I have a mainForm that has 3 panels. Panel3 is the one where I want my user control's to show. On my main form if I have a button (on left menu) I use this code and it works great:
panel3.Controls.Clear();
UserControl2 userControl2 = new UserControl2();
userControl2.Dock = DockStyle.Fill;
panel3.Controls.Add(userControl2);
My issue is when I have a button on that User Control 2 and I want that button click to bring up a UC called Employee List. It can't find panel 3. So my question is how can I tie Employee list to open up in Main Form Panel 3 or is there a better way to do that?
UPDATE: I did this and it works.. but it creates another main form with my employee list UC open now in panel3.. how can I just have it open and not create another main form?
mainForm mf = new mainForm();
mf.panel3.Controls.Clear();
employeeList empList = new employeeList();
empList.Dock = DockStyle.Fill;
mf.panel3.Controls.Add(empList);
mf.Show();
This piece of code did it!
mainForm f1 = (mainForm)Application.OpenForms["mainForm"];
f1.panel3.Controls.Clear();
employeeList empList = new employeeList();
empList.Dock = DockStyle.Fill;
f1.panel3.Controls.Add(empList);
f1.Show();
I have two forms; form 1 which contains the button button1 and MDIParent form.
By clicking the button1 I want to be redirected to the MDIparent form.
I am using the following code in click event of the button1
MDIParent f = new MDIParent();
f.ShowDialog();
However, the code gives no response when the button is being clicked.
You Must set Parent Form Property (IsMdiContainer = True)
MDIParent f = new MDIParent();
f.MdiParent = this;
f.Show();
excuse my english
well i have a Form MDI Conteiner and then i open a Child Form MDI like this
frSeries Serie = new frSeries();
Serie.Opener = this;
Serie.MdiParent = this;
Serie.Show();
seriesToolStripMenuItem.Enabled = false;
in the code above my Child Form receives the focus but when i select something from one combobox that i have in this new Form the background blink
but if i create the new form like this
frSeries Serie = new frSeries();
Serie.Opener = this;
Serie.MdiParent = this.MdiParent; //<----- this line is the problem
Serie.Show();
seriesToolStripMenuItem.Enabled = false;
the code above the Child Form don't receives the focus so i have to click in the child form and when i select something from one combobox that i have in this new Form the background not blink
i don't kown what is the correct form of open a MDI Form
I am using a SplitContainter in MDI parent Form.
My problem is I loaded a form in panel1 named First Form. In this First Form with a button I load SecondForm in panel2.
I am using this code:
Form In_but = new SecondForm();
In_but.MdiParent = this.ParentForm;
In_but.TopLevel = false;
this.splitContainer1.Panel2.Controls.Add(In_but);
In_but.Show();
But it's not working. The error is: does not contain definition splitContainer1.
From looking at your code sample, I suspect your problem is when you refer to this.splitContainer, this is your 'First form' on panel 1, and your SplitContainer is on this.ParentForm.
I'd suggest changing that line to this.(ParentForm as <whatever class your parent form is>).splitContainer1.Panel2.Controls.Add(In_but);
try this
frmChild frmChild = new frmChild();
frmChild.TopLevel = false;
frmChild.Parent = this.splitContainer3.Panel2;
frmMasterlistAdministrationAdd.Show();
frmTest fs = new frmTest(); //frmTest is the form that you going to call
fs.MdiParent = this; //the main form is a mdiform and have a splitcontainer with
//two panels
this.splitContainer1.Panel2.Controls.Add(fs); //add the fs form to the panel2
fs.Show(); //show the form