Click here to Skip to main content
Click here to Skip to main content

Use Form as Subform

, 29 Aug 2012
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Carlos1907
Software Developer (Senior) ThyssenKrupp Industrial Solutions
Brazil Brazil
I'm just another ordinary programmer.
Follow on   Twitter

Comments and Discussions

 
GeneralMy vote of 4 PinmemberChristian Amado29-Aug-12 10:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140827.1 | Last Updated 29 Aug 2012
Article Copyright 2012 by Carlos1907
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid