Delphi XE3
I have 4 charts on a tabsheet, 2 across, 2 down. When I resize the form I want the charts to resize proportionately keeping their relative position. I just can't figure out how to do it. I've tried using Anchor settings without success. When I set the anchors to Left, Top, Right and Bottom they overlap each other when resized.
Anchors won't help here. You are looking for something more akin to the Align
property. But none of the built-in options can do this layout. So, I think you are best writing a bespoke OnResize
handler.
I suggest that you put the charts in a container, say a panel. Assuming that you want the charts to fill the panel in a two by two grid, then you write the following in your panel's OnResize
event handler:
var
W, H: Integer;
....
W := Panel.ClientWidth;
H := Panel.ClientHeight;
Chart1.SetBounds(0, 0, W div 2, H div 2);
Chart2.SetBounds(W div 2, 0, W - W div 2, H div 2);
Chart3.SetBounds(0, H div 2, W div 2, H - H div 2);
Chart4.SetBounds(W div 2, H div 2, W - W div 2, H - H div 2);
You can tweak the layout as you please, but the basics of using OnResize
are the same.