Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have used Metro tools. and i have created Mdi Parent form also. when i pass "parent form" to "child form" errors message are displays. like "Only top-level controls can have an owner"

how to fix this issues? please give me solution

C#
using MetroFramework.Forms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using BillingSystem.Presentation;

namespace BillingSystem.Presentation
{
    public partial class frmMainMenu : MetroForm
    {
        public frmMainMenu()
        {
            InitializeComponent();
        }
        public void LoadForm(MetroForm frm)
        {
            frm.MdiParent = this;
            frm.WindowState = FormWindowState.Maximized;
            frm.BringToFront();
            frm.Show();                               
        }
        private void frmMainMenu_Load(object sender, EventArgs e)
        {
           
        }
    
        private void metroButton2_Click(object sender, EventArgs e)
        {
            try
            {
                LoadForm(new frmAddInvoice());
                this.WindowState = FormWindowState.Maximized;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }        
    }
}


What I have tried:

The Error's shows in "frm.show()"...
Posted
Updated 25-Aug-16 5:49am

1 solution

You're using MDI for a purpose it was not intended. Judging by the code you've posted, you don't need MDI at all. MDI is also pretty much deprecated.

MDI was intended for applications like editors, where you have multiple documents open at the same time, but the documents are all the same editor. Kind of like having multiple Notepads open but in the same application.

What is "MetroForm"? It doesn't appear as though that is an actual Form.
 
Share this answer
 
Comments
Rifath apps 25-Aug-16 12:58pm    
i have used metro framework. so i have change form as a metroForm.
Dave Kreskowiak 25-Aug-16 13:46pm    
This is a 3rd party framework you're using. You're best source of information and support on it is the maker of the framework.

I've never used it and, frankly, the "fixes" I've seen on the net for this are all "hacks" to the source code fo the Metro Framework.

You can TRY to set the TopLevel property of the form to True, but I have no idea what effects this will have on the form or the behavior of your application.

frm.MdiParent = this;
...
frm.TopLevel = true;
frm.Show();
Rifath apps 25-Aug-16 17:19pm    
Not success.. i have tried this one also like "frm.TopLevel=false".. and i tried from some developers, but not success, thanks for your feedback...
ibrahim ali asgher 22-Nov-17 6:37am    
If you found the solution, please update.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900