Unwanted form size growing on TSplitter move when Panel1.Constraints.MinHeight is set
Asked Answered
F

2

8

I have this type of situation (see image), now when I move Splitter1 up in run-time, Panel2 height grows and also Form1 height grows.

But I need to know and block this type of event, when Splitter1 can't be moved up because of Panel1.Constraints.MinHeight is reached, so Panel2 can't be changed of it's height and Form1 too.

Thanks for any help.

preview

-- Edit --
Panel1.Align := alLeft;
Splitter1.Align := alBottom;
Panel2.Align := alBottom;

Faceoff answered 1/11, 2013 at 22:4 Comment(0)
B
7

You can check and deny further sizing in splitter's CanResize event.

procedure TForm1.Splitter1CanResize(Sender: TObject; var NewSize: Integer;
  var Accept: Boolean);
begin
  Accept := ClientHeight - (NewSize + Splitter1.Height) >= Panel1.Constraints.MinHeight;
end;
Briony answered 1/11, 2013 at 22:20 Comment(1)
Thanks, this works great for me. The simplest solution is the best.Faceoff
W
1

Set the Splitter AutoSnap property to false and its MinSize property to the MinHeight of Panel1.

Whitby answered 1/11, 2013 at 22:18 Comment(5)
I have AutoSnap set to False, and ResizeStyle set to rsUpdate. I'm sorry for not mentioning of this until now.Faceoff
Then you seem to have missed to set the MinSize of the Splitter to the MinHeight of Panel1. Without that my solution will not work. Anyway, Sertac showed another valid approach.Whitby
No, I don't missed Splitter1.MinSize property. It is set to 84, this will be the min size of Panel2 when moving Splitter1 down.Faceoff
Well, the trick is to set it to the MinHeight of Panel1 (i.e. 200). It may not be what is desired, but it is a workaround for that weird bug/feature in the TSplitter implementation. TSplitter.MinSize is checked for both ends. Sertacs solution is more flexible, though.Whitby
@UweRaabe - I find it also more reliable :) because if you change the Constraints of the panel then you have to REMEMBER to update also the MinSize property of the splitter. (Hey! My Firefox spellchecker says that 'splitter' is not a valid english word!)List

© 2022 - 2024 — McMap. All rights reserved.