Reputation: 63
I get this Only top-level controls can have an owner.
exception even if I already set my child form's toplevel to false.
Here's my code for my main form:
public Form childform;
public void innerChild(Form child)
{
breaker();
childform = child;
childform.TopLevel = false;
splitContainer1.Panel2.Controls.Add(childform);
childform.Show(); //**Toplevel e**
}
private void breaker()
{
try
{
childform.Close();
childform.Dispose();
}
catch { }
}
private void btnSupProd_Click(object sender, EventArgs e)
{
innerChild(new Supplier_Supplies(this));
}
Here's the related code in my child form:
MySqlConnection conn;
public Dashboard reftomain;
public Supplier_Supplies(Dashboard main)
{
InitializeComponent();
reftomain = main;
this.TopLevel = false;
conn = new MySqlConnection("server=localhost; database=sample; uid=root; pwd=");
}
I'm trying to get the child form to show in my main form's panel. But this error keeps on persisting, help?
Stack Trace:
System.ArgumentException occurred
HResult=0x80070057
Message=Only top-level controls can have an owner.
Parameter name: value
Source=System.Windows.Forms
StackTrace:
at System.Windows.Forms.Form.set_Owner(Form value)
at MetroFramework.Forms.MetroForm.MetroShadowBase..ctor(Form targetForm, Int32 shadowSize, Int32 wsExStyle)
at MetroFramework.Forms.MetroForm.MetroFlatDropShadow..ctor(Form targetForm)
at MetroFramework.Forms.MetroForm.CreateShadow()
at MetroFramework.Forms.MetroForm.OnLoad(EventArgs e)
at System.Windows.Forms.Form.OnCreateControl()
at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl()
at System.Windows.Forms.Control.SetVisibleCore(Boolean value)
at System.Windows.Forms.Form.SetVisibleCore(Boolean value)
at System.Windows.Forms.Control.Show()
at Jacam_Merchat.Dashboard.innerChild(Form child) in C:\Users\User\Desktop\SAD 2\Jacam Merchat\Jacam Merchat\Dashboard.cs:line 37
at Jacam_Merchat.Dashboard.btnSupProd_Click(Object sender, EventArgs e) in C:\Users\User\Desktop\SAD 2\Jacam Merchat\Jacam Merchat\Dashboard.cs:line 64
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at MetroFramework.Controls.MetroTile.OnMouseUp(MouseEventArgs e)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at Jacam_Merchat.Program.Main() in C:\Users\User\Desktop\SAD 2\Jacam Merchat\Jacam Merchat\Program.cs:line 19
Upvotes: 0
Views: 3327
Reputation: 71
Tested it out.
Set shadowtype to none on the child form
Hope this helps.
Happy Coding.
Upvotes: 7