×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

resizing controls by percent

resizing controls by percent

resizing controls by percent

(OP)
Hello,

I have a UserControl with a line up of textboxes and comboboxes on it. They are lined up from left to right with the texboxes coming first and then the comboboxes

What I would like to do is allow for the UserControl to be horizontally resized and have the textboxes and comboboxes resize according to percentage. Whatever percentage they are now, they should maintain that percentage. So, for example, the left-most combobox is about 8% of the entire width of the UserControl. If the UserControl was stretched to twice its current size, the combobox should also stretch to twice its size, thereby remaining at 8% of the UserControl's width.

How can I do this?

I'm working in Visual Studios 2008.
Replies continue below

Recommended for you

RE: resizing controls by percent

I would use a TableLayoutPanel with multiple columns and one row, and place your controls within that. You can size the TableLayoutPanel columns using percents, and if the TableLayoutPanel is docked within your user control those columns should size (by percent) on the size of the UserControl. Just be sure your control Anchors are set properly (Anchor Left & Right) to automatically fill the columns width.

RE: resizing controls by percent

(OP)
Thanks very much, Borvik,

Mind if I ask one more question?

Using the TableLayoutPanel, how can I tell it to remove any space or padding between the controls so that the cell "hug" the controls and no gaps exist between controls?

Thanks again.

RE: resizing controls by percent

That would be the Textbox and ComboBox Margin properties causing that. The default margins are 3,3,3,3. If you set the left and right margins to 0, that should eliminate the gaps.

RE: resizing controls by percent

(OP)
Thanks again Borvik,

I hope you don't mind if I ask you a few more questions.

I'm having trouble controlling the initial sizes of the cells and their contents. The visual studios designer seems to be doing some pretty erradic things with the sizes and I can't really control it. One control (a textbox) had an original width of 250 pixels, but then when I place it into a cell, it reduces to 60. I can't manually adjust the width back to 250 in the properties because it reverts it back to 60. The cell borders won't move when I dry to drag them.

Programmatically, I'm not sure how to access each cell individually and set their widths in terms of percent.

I need either: 1) to set the control to a particular width and have the table cells conform to those widths, or 2) set the table cells to a certain width (in terms of percentage) and have the control conform to those widths.

Any help would be very much appreciated. Thanks.

RE: resizing controls by percent

You can use the Visual Designer of the UserControl itself.

With the TableLayoutPanel selected in the Properties window (the status area of it) click on Edit Rows and Columns. This window will allow you to control the column sizes: absolute widths, autosize to contents, or percentages.

As for the default width. In the Visual Designer of the UserControl, with the UserControl itself selected, change the default width of this until the controls are the proper width in their columns. This should be the default width of the UserControl when you add it to your forms, and the sizes should be more what you are expecting.

RE: resizing controls by percent

The Edit Rows and Columns link


The Edit Window

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close