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

  • Home
  • SEARCH
  • 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 6694133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:04:00+00:00 2026-05-26T06:04:00+00:00

If I want to create a winform with dynamic UI controls appearing, what’s the

  • 0

If I want to create a winform with dynamic UI controls appearing, what’s the best way to do that?

I have a form with a textbox, a button1 to the right of it, a listbox underneath, and a button2 underneath the listbox. Pressing button1 should generate another textbox underneath the first textbox and the listbox/button2 should be shifted down. If anyone’s used Adobe Bridge before, the batch rename window is an example of what I’m talking about.

I was thinking of simply adding textboxN.Height to this.Size, then textboxN.Height to each of the controls (except the first textbox) Y position so they all get shifted down by textboxN.Height pixels. But I think there’s a better way of doing this. Rather, is Winforms suitable for something like this?

  • 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-05-26T06:04:00+00:00Added an answer on May 26, 2026 at 6:04 am

    You -could- just add the height of the TextBox to the form’s size, but tbh it would be better to use a constant that dictates the size of the TextBoxes, and then add that.

    For moving the listBox/button2, anchor them to the bottom of the form, and they’ll automatically stay at the same distance from the bottom of the form.

    As for dynamic generation, use a List (or a Stack, depending on what exactly you’re doing with it).

    partial class Form1 : Form
    {
        List<TextBox> textBoxes = new List<TextBox>(); // or stack
        const int textBoxWidth = 200;  // control variables for TextBox placement
        const int textBoxHeight = 50;
        const int textBoxMargin = 5;
    
        void button1_Click(object sender, EventArgs e)
        {
            this.Height += textBoxHeight + textBoxMargin;
            TextBox tb = new TextBox();
    
            if (textBoxes.Count == 0)
            {
                tb.Top = textBoxMargin;
            }
            else
            {
                tb.Top = ((textBoxHeight + textBoxMargin) * textBoxes.Count) + textBoxMargin;
            }
    
            tb.Left = textBoxMargin;
            tb.Height = textBoxHeight;
            tb.Width = textBoxWidth;
            textBoxes.Add(tb);
            this.Controls.Add(tb);
        }
    }
    

    That should work. The thing with the method here is pretty much all of the placement customisation can be done with the constant values.

    Is it best to do it in WinForms? Well, there’s certainly no real reason to not do it in WinForms, this functionality is easy enough to implement. I’m a WPF guy myself but this is still legit.

    Edited for logic errors

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

Sidebar

Related Questions

I'm using a winForm. I have 2 custom controls that I want to add
I want to create a WinForm application that must draw data coming from a
I want to create a background worker for a WinForm that triggers code whenever
I want to create a winform component that contains a collection of other elements,
I want to create a .NET Form at runtime, add buttons and other controls
I have a WinForm that I create that shows a prompt with a button.
i want create image animation , i have 50 images with png format now
I want to create a stored procedure (on SQL Server 2005) that fetches a
I installed the new Visual Studio 2010. I want to create a C# Winform
We have a winform app that has been in development for some time. It

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.