Raith
Raith

Reputation: 871

How do I keep a control at the bottom or right of a panel when the panel changes size?

There have been a few similar questions with solutions, but none answered my question, so here it is.

Making a TPanel collapse/expand with a TButton on it is ridiculously simple, or so I thought. I played around and by putting the button at the very top (for expansion/collapse of height from top to bottom) or left (for expansion/collapse of width from left to right) everything worked as planned. In fact all of the expandable/collapsible "advanced" panels work in the exact same way - the button is placed on top or left only. Soon enough I hit a wall: if you put the button at the bottom or right for expansion/collapse of height or width respectively, the buttons stay where they are on... the client area (?) - I lack the knowledge to explain this properly, but I'll presume that it is clear what is happening until otherwise pointed out. The point is that with the way I'm doing this the only solution would be to reposition the button within the panel, but that might put in on top of say some other components which should not be visible at all.

So the question is: how can I make this happen properly? as my idea of resizing the panel and then repositioning the button doesn't look like a proper approach to this problem. Alternatively, I'd gladly take some component that does this, however from the components that I have checked out, all act the same, even JEDI VCL TJvRollOut component can set Placement (of the button/caption) only to plTop or plLeft, so I'm thinking this isn't as simple to do?

Upvotes: 3

Views: 3582

Answers (2)

magarwal
magarwal

Reputation: 574

There are two properties for adjusting the alignment of any tool in delphi:

  1. Align (alNone, alLeft, alRight, alTop....)

  2. Anchors (akLeft, akRight, akTop, akBottom)

e.g. You have a panel and drag a TEdit on the TPanel. Now, you want TEdit to occupy ONLY top-left corner of TPanel and its distance form the bottom and right corners of the panel should remain constant irrespective of changing the panel size (which means TEdit expands if you extent panel along the bottom or right corners).

  1. Set Align-> alNone. (not alLeft or else tEdit would occupy entire left region on panel and not just top-left).
  2. Set Anchors-> akLeft=akTop=akRight=akBottom=True. In case you set akLeft=akTop=True and akRight=akBottom=False: then the size of TEdit remains constant on expanding panel along the bottom or right corners.

Upvotes: 0

TLama
TLama

Reputation: 76693

Set to your button Anchors property to [akLeft, akBottom].

enter image description here

Upvotes: 6

Related Questions