Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is it possible to anchor a control to another control?

Is it possible to anchor a control to another control?

Lets say i want my Button1 to keep its 4px distance from Textbox1 control without
using FlowLayoutTable control?

"Why would be this advantageous?" - one could ask

Well let's say you have a SplitContainer with a vertical splitter and you have Textboxes
in SplitContainer.Panel1 which are anchored to the left and right but their maximum size's
width is smaller than you allow to the SplitContainer.Panel1's width to have (maybe
because you want text to show up there or because additional padding or whatever,you name it)

Now let's say you also have a button next to Textbox1 and you dont want Textbox1 to be
overlapped by the Button1 because its extends to far.

If i want to have my textbox fill the SplitContainer.Panel1 in a fashion that it leaves space for
Button1 control while still both of them are anchored to the right how would i do it?

like image 488
Qqbt Avatar asked Aug 28 '11 18:08

Qqbt


1 Answers

I extensively use TableLayoutPanels and FlowLayoutPanels to accomplish this. For you specific circumstance I would use a TableLayoutPanel with three columns and a row for each TextBox.

Column 1: Auto-width, contains Labels all with AutoSize = True.
Column 2: 100% width, contains TextBoxes all with Anchor = Left, Right.
Column 3: Auto-width, contains the Button in the appropriate row.

Next, I set all text boxes, except for the one next to the button, ColumnSpan = 2. Then just put the TableLayoutPanel in the SplitPanel and set Dock = Fill.

like image 117
Hand-E-Food Avatar answered Oct 21 '22 14:10

Hand-E-Food