Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why does this formresize code not act as expected?

Status
Not open for further replies.

CADTenchy

Technical User
Dec 12, 2007
237
GB

I have a form with two panels separated by a splitterbar.

In the code below, EntryPanel is leftmost, and aligned left.
Then comes AdvSplitter1, also aligned left.
Finally InfoPanel, which is aligned client.
ClientBorder is an integer calculated on formcreate, in case the amount of pixels in the client border changes with users' Windows settings. It's calculated by a simple sum.

EntryPanel has a minimum width constraint set, so it can't be made smaller than the space required to dispay its edit boxes.

What I'm trying to do below is keep the width of InfoPanel constant, and therefore move position of AdvSplitter1 relative to the form right side, until EntryPanel width hits the minimum constraint.

What actually happens is as soon as you start resizing the form EntryPanel snaps to the position of it's minimum constraint and stays fixed, with AdvSplitter1 moving up against it as it should, then InfoPanel resizes accordingly as you resize the form.

I can't see why this should happen?

Code:
procedure TMainForm.FormResize(Sender: TObject);
begin
InfoPanel.Left := MainForm.ClientWidth - InfoPanel.Width - ClientBorder;
AdvSplitter1.Left := InfoPanel.Left - 6;
EntryPanel.Width := MainForm.ClientWidth - AdvSplitter1.Left - ClientBorder;
end;


Steve (Delphi 2007 & XP)
 
I think what is messing you up is the order in which things occur.

The OnResize event occurs after all the form's controls have been repositioned, but before they are painted.

You should take a look at the OnCanResize event, which occurs before any actual resizing happens to child controls (and is a good place to do your manipulations).

Another useful event is the OnConstrainedResize event, which is useful when handling individual child controls. In your case, I wouldn't use this one.

Hope this helps.
 

Thanks for that. I guess I should have investigated the OnCanResize events, I didn't know what the difference was, so I've been going for the obvious ones!


Steve (Delphi 2007 & XP)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top