what is this error :
Form that was specified to be the MdiParent for this form is not an MdiContainer.
Parameter name: value
here is the code
public partial class Form5 : Form
{
public Form5()
{
InitializeComponent();
}
private void Form1_MdiChildActivate(object sender, EventArgs e)
{
if (this.ActiveMdiChild == null)
tabForms.Visible = false; // If no any child form, hide tabControl
else
{
this.ActiveMdiChild.WindowState = FormWindowState.Maximized; // Child form always maximized
// If child form is new and no has tabPage, create new tabPage
if (this.ActiveMdiChild.Tag == null)
{
// Add a tabPage to tabControl with child form caption
TabPage tp = new TabPage(this.ActiveMdiChild.Text);
tp.Tag = this.ActiveMdiChild;
tp.Parent = tabForms;
tabForms.SelectedTab = tp;
this.ActiveMdiChild.Tag = tp;
this.ActiveMdiChild.FormClosed += new FormClosedEventHandler(ActiveMdiChild_FormClosed);
}
if (!tabForms.Visible) tabForms.Visible = true;
}
}
// If child form closed, remove tabPage
private void ActiveMdiChild_FormClosed(object sender, FormClosedEventArgs e)
{
((sender as Form).Tag as TabPage).Dispose();
}
private void tabForms_SelectedIndexChanged(object sender, EventArgs e)
{
if ((tabForms.SelectedTab != null) && (tabForms.SelectedTab.Tag != null))
(tabForms.SelectedTab.Tag as Form).Select();
}
private void projectsToolStripMenuItem_Click(object sender, EventArgs e)
{
Form7 f7 = new Form7();
f7.MdiParent = this;
f7.Show();
}
}
The problem is probably that in your Form5 class you are not specifying that the Form is a MdiContainer.
Try setting the IsMdiContainer property to true or set the property manualy after you call InitializeComponent in the constructor.
Related
I have this method(below) that works well First time it's called:
public void showForm(Form _form, Form _main)
{
if (_main != null)
{
foreach (Form otherForms in this.MdiChildren)
{
otherForms.Close();
}
}
_form.MdiParent = this;
_form.Dock = DockStyle.Fill;
_form.TopLevel = false;
_form.TopMost = true;
_form.FormBorderStyle = FormBorderStyle.None;
this.MDIChildPanel.Controls.Add(_form);
_form.BringToFront();
_form.Show();
}
on Form_Load event for MDI Parent Form i call the method above as shown below and it works well:
private void MDIRental_Load(object sender, EventArgs e)
{
showForm(new Login(), null);
}
I then try to call the method above from another event handler and it just doesnt work as show below: help
private void manageUsersToolStripMenuItem_Click(object sender, EventArgs e)
{
showForm(new Users(), null);
}
I have a List view inside a user control, that user control placed inside MDI form, now what i have to do is i have to populate the list view based on the MDI menu click. i tried the below method but its not working, the method getting triggered but the list view not getting update. Here is my sample code
User control
public ucQuickLaunch()
{
InitializeComponent();
ListFill("Loaded..");
}
public void ListFill(string Message)
{
try
{
ListViewItem myitem = new ListViewItem();
myitem.Text = DateTime.Now.ToLongTimeString().ToString();
myitem.SubItems.Add(Message);
ListViewStatus.Items.Add(myitem);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
MDI Menu click
public ucQuickLaunch objQuickLaunch=new ucQuickLaunch();
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmGeneral frm = new FrmGeneral();
FrmGeneral open = Application.OpenForms["FrmGeneral"] as FrmGeneral;
if (open == null)
{
frm.MdiParent = this;
frm.Show();
objQuickLaunch.ListFill("General button clicked");
}
else
{
open.Activate();
if (open.WindowState == FormWindowState.Minimized)
{
open.WindowState = FormWindowState.Normal;
}
}
}
I assume you have your custom control (ucQuickLaunch ) placed on your form (FrmGeneral). If so you need to add method for filling that control to your form:
public partial class FrmGeneral : Form
{
public FrmGeneral()
{
InitializeComponent();
}
public void ListFill(string value)
{
objQuickLaunch.ListFill(value);
}
}
and your menu:
private void newToolStripMenuItem_Click(object sender, EventArgs e)
{
FrmGeneral open = Application.OpenForms["FrmGeneral"] as FrmGeneral;
if (open == null)
{
FrmGeneral frm = new FrmGeneral();
frm.MdiParent = this;
frm.ListFill("General button clicked");
frm.Show();
}
else
{
open.Activate();
if (open.WindowState == FormWindowState.Minimized)
{
open.WindowState = FormWindowState.Normal;
}
}
}
I am using SplitContainer tool in C# window application
I want to replace one Form for other form in splited Container panel
How can I do this?
I want to do in From From1 works finishes it work and show From2.. replace same place of splited container panel...
but this code not working...
public partial class Parent : Form{public Parent()
{
InitializeComponent();
}
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e)
{
TreeNode node = treeView1.SelectedNode;
if (node.Text.ToString().Equals("Control1"))
{
//MessageBox.Show(node.ToString());
//Control1 conr1 = new Control1();
ShowForm(1);
}
else if (node.Text.ToString().Equals("Control2"))
{
//MessageBox.Show(node.ToString());
//Control2 conr2 = new Control2();
ShowForm(2);
}
}
public void ShowForm(int id)
{
Form childObj = null;
if (id == 1)
{
childObj = new Control1();
}
else
{
childObj = new Control2();
}
childObj.TopLevel = false;
childObj.Visible = true;
childObj.Parent = this.splitContainer1.Panel2;
this.splitContainer1.Panel2.Controls.Clear();
this.splitContainer1.Panel2.Hide();
this.splitContainer1.Panel2.Controls.Add(childObj);
this.splitContainer1.Panel2.Show();
childObj.Show();
}
public Control2()
{
InitializeComponent();
}
Parent bioAdMainForm = new Parent();
private void button1_Click(object sender, EventArgs e)
{
//Control1 enrollmentForm = new Control1();
//this.Hide();
//enrollmentForm.Show();
bioAdMainForm.ShowForm(1);
}
You can't place Form into Panel. Forms are intended to be displayed in separate window. You should use UserControl descendants instead of forms to achieve what you want.
I have a form with a button in it. If i click the button another form opens. If I return to the parent form with the help of tab and click the same button again it does nothing.
Here is my code:
private void pictureBox1_Click(object sender, EventArgs e)
{
form wadd = new form(this);
if ((IsFormAlreadyOpen(typeof(form))) == null)
{
wadd.MdiParent = Form1.ActiveForm;
wadd.Show();
}
}
public static Form IsFormAlreadyOpen(Type FormType)
{
foreach (Form OpenForm in Application.OpenForms)
{
if (OpenForm.GetType() == FormType)
return OpenForm;
}
return null;
}
private void Form1_MdiChildActivate(object sender, EventArgs e)
{
if (this.ActiveMdiChild == null)
tabForms.Visible = false;
// If no any child form, hide tabControl
else
{
this.ActiveMdiChild.WindowState = FormWindowState.Maximized;
// Child form always maximized
// If child form is new and no has tabPage,
// create new tabPage
if (this.ActiveMdiChild.Tag == null)
{
// Add a tabPage to tabControl with child
// form caption
TabPage tp = new TabPage(this.ActiveMdiChild.Text);
tp.Tag = this.ActiveMdiChild;
tp.Parent = tabForms;
tabForms.SelectedTab = tp;
this.ActiveMdiChild.Tag = tp;
this.ActiveMdiChild.FormClosed += new FormClosedEventHandler(ActiveMdiChild_FormClosed);
}
else
{
tab();
}
if (!tabForms.Visible) tabForms.Visible = true;
}
}
public void tab()
{
for (int i = 0; i < tabForms.TabCount; i++)
{
if (tabForms.TabPages[i].Text == this.ActiveMdiChild.Text.ToString())
{
tabForms.SelectedTab = tabForms.TabPages[i];
break;
}
}
}
private void ActiveMdiChild_FormClosed(object sender, FormClosedEventArgs e)
{
//Destroy the corresponding Tabpage when closing MDI child form
if (tabForms.HasChildren)
{
((sender as Form).Tag as TabPage).Dispose();
}
//If no Tabpage left
else if (!tabForms.HasChildren)
{
tabForms.Visible = false;
}
}
private void tabForms_SelectedIndexChanged(object sender, EventArgs e)
{
if ((tabForms.SelectedTab != null) && (tabForms.SelectedTab.Tag != null))
(tabForms.SelectedTab.Tag as Form).Select();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (!tabForms.HasChildren)
{
Application.Exit();
}
}
The result I want is when I click the button again the tab should gets focused to this form rather than opening new form which is not permissable.
I think you'd want something like this:
public Form FormOpened<T>()
{
foreach (Form form in Application.OpenForms)
if (typeof(T) == form.GetType())
return form;
return null;
}
You could then use it like this:
form f = (form)FormOpened<form>();
if (f2 == null)
{
f2 = new form();
f2.MdiParent = this;
f2.Show();
}
else
{
f2.Focus();
}
Tell me if you need any help.
You want something like this I believe:
form wadd;
private void pictureBox1_Click(object sender, EventArgs e)
{
if (wadd == null)
{
wadd = new form(this);
}
wadd.MdiParent = Form1.ActiveForm;
wadd.Show();
}
You just have the logic backwards. If there is no form open, then create it then open it. If there is a form already then just use it.
I need to hide a panel on the Parent Form when a Child Form on an MDI Parent Form closes & show back the panel on the Parent form when the Child Form is closed.
Currently am using SendtoBack() to show the Child Form infront of the Panel which is on the Parent Form , but when i close the Child Form, then the Panel doesn't appears back, even if i use :
BringtoFront()
OR
Panel1.Visible=true
public partial class CHILD : Form
{
private void CHILD_Load(object sender, EventArgs e)
{
this.FormClosed += new FormClosedEventHandler(CHILD_FormClosed);
}
void CHILD_FormClosed(object sender, FormClosedEventArgs e)
{
PARENTForm P = new PARENTForm();
P.panel1.BringToFront();
P.panel1.Visible = true;
}
}
public partial class Form1 : Form
{
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
CHILD P = new CHILD();
P.Showg();
P.MdiParent = this;
P.BringToFront();
panel1.SendToBack();
panel1.Visible = false;
}
}
THIS ISN'T WORKING....PLEASE HELP..!
You creating new parent form in child form. You need to pass parent form object to child form and then use it to show/hide panel and set panel Modifiers property to public.
For example...
Parent form:
public partial class ParentForm : Form
{
public ParentForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
panel1.Visible = false;
ChildForm childForm = new ChildForm();
childForm.MdiParent = this;
childForm.Show();
}
}
Child form:
public partial class ChildForm : Form
{
public ChildForm()
{
InitializeComponent();
}
private void Child_FormClosed(object sender, FormClosedEventArgs e)
{
ParentForm parentForm = (ParentForm)this.MdiParent;
parentForm.panel1.Visible = true;
}
}
Use this Code
in Parent Form
private void MainMenu_ChildForm_Click(object sender, EventArgs e)
{
ChildForm frm = new ChildForm();
frm.MdiParent = this;
ShowHideMainPanel(frm);
frm.Show();
}
void ShowHideMainPanel(Form frm)
{
frm.FormClosed += new FormClosedEventHandler(Form_Closed);
panel1.Visible = false;
}
void Form_Closed(object sender, FormClosedEventArgs e)
{
panel1.Visible = true;
}
by assigning close event for child to show panel after its closing