Reputation: 21
//MdiParent mainparent.cs public static void lodforweb() { frm_webcs frmload_webcs = new frm_web { MdiParent = this }; frmload_webcs.Show(); } //Context menu class //Cl_contextmenu.cs public bool OnContextMenuCommand() { if (commandId == (2020) { mainparent.lodforweb(); return true; } }
}
// having a problem with "this" using static method // instantiating does not work also.
Upvotes: 1
Views: 121
Reputation: 39132
From the comments:
once I right click the child form context menu popups. I want to generate another child form and should be child of mainparent
Also provided from the comments:
private void childform_Load(object sender, EventArgs e) {
cl_chromebrowser urload = new cl_chromebrowser();
panel1.Controls.Add(urload.choniumeload("www.site.com"));
urload.chromebrowser.MenuHandler= new cl_contexmenu();
}
So your child form is called "childform". Add a static member that holds a reference to the MDI parent, and set it in the Load() event:
public static Form MyMdiParent;
private void childform_Load(object sender, EventArgs e)
{
// ... your existing code from above ...
childform.MyMdiParent = this.MdiParent;
}
Now you can use that MDI parent directly from your context menu:
public bool OnContextMenuCommand()
{
if (commandId == 2020)
{
if (childform.MyMdiParent != null)
{
childform.MyMdiParent.Invoke((MethodInvoker)delegate ()
{
frm_webcs frmload_webcs = new frm_webcs();
frmload_webcs.MdiParent = childform.MyMdiParent;
frmload_webcs.Show();
});
}
}
return true;
}
Upvotes: 0