Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Use Form as Subform

0.00/5 (No votes)
29 Aug 2012 1  
This is an alternative for Use form as subform

Introduction

This is a shortcut to the original trick from Antonio Lopez R: Use form as subform

Background

I highly recommend that you read Antonio's article and understand it. I love embed common functions into extensions, because the code becomes very easy to read.

At first, I'll try this way:

static class SubFormExtensions
{
    internal static bool AttachTo(this Form subForm, Panel panel)
    {
        if (panel == null || subForm == null) return false;
        subForm.FormBorderStyle = FormBorderStyle.None;
        subForm.TopLevel = false;
        subForm.ShowInTaskbar = false;
        subForm.Show();
        subForm.Dock = DockStyle.Fill;
        panel.Controls.Add(subForm);
    }
}

Using the Code

What I'm doing here is just using extensions to make things clear. Using the same example as Antonio, you can call this way:

var SubForm = new frmReportsAndCharts();
SubForm.AttachTo(panel1);

Points of Interest

This is my first test writing an article, so feel free to point anything strange here.

History

2012-06-12: First version of article.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here