Embedding a form within a C# form.

Posted on 2007-10-09
Last Modified: 2013-11-23
I need to open an MDI child form in a C# MDI application.

The problem is that this MDI child form is loaded via reflection from a Delphi.NET assembly. Despite my best efforts, this just does not work. At All. Period. Regular forms are fine, MDI children are most certainly not.

But I really, really, really need this to work.

So, I'm, trying to find a different approach.

Is there any way to embed a form in another form? For example, in delphi, there is  a component called a FormPanel. This allows a form to be placed within in it, acting as its container. Is there something similar in C# (or any other .NET language)?

Thanks for any help at all.


Question by:steve-west
    LVL 11

    Accepted Solution

    You can try using the Com SetParent Function(). Example:
    //First import the function from COM+
    static extern IntPtr SetParent(IntPtr hWndChild, IntPtr hWndNewParent);

    //then add it to our form

    Form FrmChild = new Form();
    FrmChild.Text = "Test form";
    SetParent(FrmChild.Handle, this.Handle);

    Hope this helps!


    Author Comment


    Thanks for this - on the face of it it's just what I'm after. However, it doesn't seem to work for C# Mdi Child forms.

    if I load a form from delphi and reparent it within a standard c#  FormX, it appears within FormX

    If FormX then has MDIParent = this, the reparented form doesn't seem to appear.


    Author Comment

    Actually forget what I've just said - it does work, well done.

    Thanks a lot.

    LVL 11

    Expert Comment

    by:Mihai Stancescu
    You're welcome.


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
    Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now