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 7885349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:02:41+00:00 2026-06-03T05:02:41+00:00

I am trying to evenly space dynamically created controls by giving them a width

  • 0

I am trying to evenly space dynamically created controls by giving them a width and height that is a fraction of the width and height of the container control.

However, although my functions calculating the dimensions are correct, for some reason the assignment to the Width property is being stubbornly refused. The WidthToUse() function is returning 19, yet when an attempt is made to assign that vaue to the dynamically created TextBox, it remains at…630! Why 630 to begin with, and why does it refuse to be assigned to?

Even the height, although “working” doesn’t work quite right – there are too many controls or not enough space on the panel to accommodate all of the controls using this math.

Here’s my code:

int WidthToUse = getTextBoxWidthToUse(tableLayoutPanelGreatGooglyMoogly.Width);
int HeightToUse = getControlHeightToUse(tableLayoutPanelGreatGooglyMoogly.Height);

TextBox txtbx = new TextBox();
txtbx.Parent = tableLayoutPanelGreatGooglyMoogly;
txtbx.Margin = new Padding();
txtbx.Dock = DockStyle.Fill;
txtbx.AutoSize = false;
txtbx.Width = WidthToUse;   // WidthToUse is 19, but txtbx.Width is 630 both before AND after this assignment!
txtbx.Height = HeightToUse; // HeightToUse is 27


private static int getControlHeightToUse(int theDynPanelHeight) {
    return (theDynPanelHeight / NUMBER_OF_ROWS);
}

private static int getTextBoxWidthToUse(int theDynPanelWidth) {
    return (theDynPanelWidth / 32);
}

private static int getLabelWidthToUse(int theDynPanelWidth) {
    return ((theDynPanelWidth / 64) * 3);
}
  • 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-03T05:02:43+00:00Added an answer on June 3, 2026 at 5:02 am

    DockStyle.Fill is a property describing the size of a control relative to the size of it’s container. A control will resize to fit all of the empty space in it’s parent container with this property set.

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

Sidebar

Related Questions

I'm trying to lower the size of thumbnails to get them to evenly fit
i am trying to spread 4 items evenly across its parent container but for
I'm trying to check if each number in a list is evenly divisible by
Trying to get comfortable with jQuery and I have encountered some sample code that
I am trying to get 2 buttons to be beside each other and evenly
I'm trying to represent an array of evenly spaced floats, an arithmetic progression, starting
I'm trying to find a simple method of getting all the links spread evenly
I'm trying to setup a ListBox so that every item has a textblock and
I am trying to create an android layout that uses about 1/3 of the
I'm trying to create a horizontal navigation bar in css with 5 evenly spaced

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.