Reputation: 1232
In the WinForm I am working on, I have two TextBox widgets and one button between the text boxes. When the form starts, and the winform is at its minimum size, the TextBoxes look as expected. No gaps between the items where they come close to the button there in the center. This is as seen in the top graphic.
However, when the user maximizes the winform, the TextBoxes move to the correct position but do not expand to keep close to the button in the center. Textbox A is anchored to the left and Textbox B is anchored to the right. So the alignment is correct. This is as seen in the bottom graphic.
Now, the question is how to make text box A grow to the right so that it comes close to the button in the middle and text box B grow to the left so that it also comes close to the button?
Thanks! Eric
Upvotes: 2
Views: 1064
Reputation: 32445
Use TablelayoutPanel
control. From MSDN
Create TableLayoutPanel
with one row and three columns
First column: SizeType:
percent, 50%
Second column: SizeType:
absolute, 75(button width)
Third column: SizeType:
percent, 50%
Then put textboxes and button in the columns.
Set for textboxes and button property .Dock = Fill
Size of the textboxes will be automatically changed with size of the columns in the TableLayoutPanel
Set Dock
property of the TableLayouPanel
to Fill
or Bottom
or Top
. Then TableLayoutPanel will change width when width of the form is changed.
Upvotes: 2
Reputation: 18023
With simple anchors you cannot achieve this.
But you can use a TableLayoutPanel
:
TableLayoutPanel
on the form and set Dock
to Fill
(or Top
/Bottom
)Without a TableLayoutPanel
, you can make the following:
Upvotes: 3
Reputation: 471
you can use the Anchor Property for Button and textbox -
Button A - Anchor - left and Right Button B - Anchor - left and Right
you can also, set textbox anchor property as per your needs and control the location of all these three controls.
Upvotes: 0