Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8811939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:29:08+00:00 2026-06-14T03:29:08+00:00

I am adding controls after the shown event on Form. The controls are showing

  • 0

I am adding controls after the shown event on Form. The controls are showing up one at a time despite the fact I called SuspendLayout(). How can I get the layout to suspend so the controls only display when they are all finished loading?

 public partial class ControlCreateTest : Form
{
    public ControlCreateTest()
    {
        InitializeComponent();       
    }

    private void AsyncControlCreateTest_Shown(object sender, EventArgs e)
    {
        CreateControls();
    } 

    private void CreateControls()
    {
        SuspendLayout();
        int startPoint= 0;            
        for (int i = 0; i < 4; i++)
        {          
            UserControl control = new UserControl() { Text = i.ToString(), Height = 100, Width = 100 };
            control.Load += control_Load;
            Controls.Add(control);
            control.Top = startPoint;
            startPoint += control.Height;
        }

        ResumeLayout();
        Text = "Loading complete";
    }

    void control_Load(object sender, EventArgs e)
    {
        Thread.Sleep(500);
        RichTextBox newRichTextBox = new RichTextBox() { Height = 100, Width = 100 };
        UserControl control = sender as UserControl;
        control.Controls.Add(newRichTextBox);
        newRichTextBox.Text = "loaded";
    }     
}

UPDATE
It seems that once these forms begin loading…the visibility and suspend calls are thrown out the window immediately. That is quite troublesome when the Load events are long running.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T03:29:09+00:00Added an answer on June 14, 2026 at 3:29 am

    Getting a little hacked at the obscurity of Winforms dev. Anyway…I set the width and height of the form to 1 pixel in the constructor. When show is called I hide the window and put the window back to normal size. It’s hard to notice the tiny window before it’s hidden.

    This lets my routines fire up and loading form display without all the headache.

    UPDATE
    When using ShowDialogue(), this dumb little trick only works if you Set Visible = true before Form_Shown returns control to the caller. I found that if you set Visible = true in Form.Shown the Closing event will be triggered…man I flipping love WINFORMS….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just have a few questions about programmatically adding controls in aspx . After
I'm adding HTML controls dynamically using java script. For instance, I have one button
Relates to the problem Adding event handler in main() for SerialPort After I change
While I was adding controls to a VSTO MS Word template in Visual Studio,
I have a .aspx page that loads three separate .ascx controls to represent adding,
I have a TreeView control on a form. I am dynamically adding new TreeNodes
I've ran into one small problem. I am dynamically generating some controls and place
I am adding HTML input controls on the page dynamically via a add text
I have a DropDownList which I initialize in a function called CreateChildControls before adding
I have a thumbnail control where I am adding Images using openfiledialog and after

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.