Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a label and textbox layout nicely when window is resized?

I have a label and a textbox in my Winform. They are one line.

in

What I want to do is to make the textbox always fill-in the available space between the label and the right border of the container, even when window is resized

The label is set to be AutoSize because it has different width in different languages.

I tried the flow layout, and I also tried various combinations of dock/anchor in both elements, but still can't make it work. If there is not simple solution (beside program coding resizing myself), is there a less optimal solution? Thanks.

like image 312
lulalala Avatar asked Jun 30 '11 13:06

lulalala


2 Answers

if it's only those 2 elements that need to be auto-layouted try this:

take a table layout panel with 2 columns and one row ... your label goes in one cell, the textbox in the other ... dock both elements (dock fill) and set the column the label is in to autosize

dock the whole panel to whatever element you want (probably your form)

you may want to add some padding to your label

like image 60
DarkSquirrel42 Avatar answered Nov 06 '22 20:11

DarkSquirrel42


I would put the controls in a panel. Set the panel to the appropiate height. Set the label to autosize and dock it left. Set the textbox dock to fill.

like image 1
John Laffoon Avatar answered Nov 06 '22 20:11

John Laffoon