簡體   English   中英

C#:只有頂級控件可以擁有所有者。 (地鐵框架)

[英]C#: Only top-level controls can have an owner. (Metro framework)

我明白了, Only top-level controls can have an owner. 即使我已經將子窗體的頂層設置為false也會發生異常。

這是我的主要形式的代碼:

    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));
}

這是我的孩子形式的相關代碼:

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=");
        }

我試圖讓子窗體顯示在主窗體的面板中。 但是這個錯誤一直持續存在,有幫助嗎?

堆棧跟蹤:

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

測試了一下。

在子窗體上將shadowtype設置為none

希望這可以幫助。
編碼愉快。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM