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
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 C#, .net, Windows Forms application. I have a form set as an MDI container on which I dynamically add buttons. Clicking a button opens a child form. However, the buttons I created appear on top of the child form instead of the child form appearing over (and covering) everything on the parent form. What am I doing wrong?
Here's how I add the buttons to the form:
Button btn1 = new Button();
btn1.BackColor = ColorTranslator.FromHtml("#456EA4");
btn1.Text = department.DepartmentName;
btn1.Location = new System.Drawing.Point(posX, posY);
btn1.Size = new System.Drawing.Size(sizeX, sizeY);
btn1.Font = new System.Drawing.Font("Calibri", 40F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
btn1.ForeColor = Color.WhiteSmoke;
btn1.TabStop = false;
this.Controls.Add(btn1);
Here's is where I open the child form:
frmToBuildFromSchedule frmToBuild = new frmToBuildFromSchedule(department);
frmToBuild.FormClosed += new FormClosedEventHandler(frmToBuildFromSchedule_FormClosed);
frmToBuild.MdiParent = this;
frmToBuild.Show();
Here is the result:
You are putting the buttons directly on the parent MDI form, which is not typical of an MDI style application. Instead, put the code that is currently in the click event of your buttons in a menu option or a ribbon button (those can also be dynamically created).
Alternatively, create a child form, maximize it, and place your buttons on that.
I think the answer by sam on the posted duplicate link is interesting. Rather than using MDI, set form.TopLevel = false; and add the form as a child control. I'm not sure if there are any downsides to this approach.
Form fff = new Form();
fff.Controls.Add(new Button { Text = "Button1" });
fff.Load += delegate {
Form ffff = new Form { TopLevel = false };
fff.Controls.Add(ffff);
ffff.Visible = true;
ffff.BringToFront();
};
Application.Run(fff);
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();
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