WinForms and UserControls

Posted on 2012-08-14
Last Modified: 2012-08-14
Just getting back into WinForms.  All my recent experience is in Web Apps.

I want to load userc controls into my form based on Button or menu item clicks.

Now I KNOW this is a very broad question...

But is the process pretty much the same as in ebApps?

Add a placeholder and load the usercontrols into that?

Any guidance on "best practice" is greatly appreciated.
Question by:lrbrister
    LVL 83

    Accepted Solution

    Yeah its similar. Just instantiate the control, add it to a container such as form, set its location and you are done.
    LVL 85

    Assisted Solution

    by:Mike Tomlinson
    For the simplest of cases, you can simply instantiate the controls and add them to your desired container after setting the Location() and/or Size().  Sometimes you may want to increase the size of your container via code as well.

    For more complicated scenarios, where you need other existing controls to move around, then you may want to look at using things like the FlowLayoutPanel() or the TableLayoutPanel() which gives you finer control over how controls are laid out with respect to each other.

    Another tidbit is to set the AutoScroll() property of a container to True if you want scrollbars to appear automatically on it when controls are out of the visible area.  For example, if you added a series of buttons to a Panel, each one below the previous one, and they exceeded the height of the Panel, then a vertical scrollbar would appear allowing the user to scroll the panel down to the non-visible buttons.

    Author Closing Comment

    Great. Thanks folks.
    Expect more questions to come about seemingly simple things

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
    Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    755 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

    21 Experts available now in Live!

    Get 1:1 Help Now