Question

I have a problem I am unable to solve even though I spend long time trying to do it.

I usually use GridPanels to align controls on forms. It has, however, an annoying bug. When the GridPanel align mode is alClient and I maximize its parent window, the GridPanel adjusts to the new size of that window, however, the controls laying on the grid do not. They stay in the same position they were before window resize. It happens only at the first window's maximization. If the window is first resized manually, everyting is OK. I think the grid adjusts its child controls after the second resize event (??).

What to to do make GridPanel work properly if it comes to this bug? It might be enough to send a message to it (but what message?), I do not know. I tried to use Realign, Refresh etc., but they did not help.

Thanks for your help in advance,

Mariusz.

Was it helpful?

Solution

Ah, I've had similar issues as well. It might be related to a resizing problem in the VCL. You might want to try the fix by Andreas Hausladen. It seems to work for me in most of the cases.

OTHER TIPS

I found one trick.

in OnResize event of parent of gridpanel, change gridpanel's width by 1 pixel.

then gridPanel will notice size changed, then rearrange sub-controls in gridpanel..

sample is below..

procedure TForm1.FormResize(Sender: TObject);
begin
  GridPanel1.Width := GridPanel1.Width - 1;  // subtract 1
  GridPanel1.Width := GridPanel1.Width + 1;  // recover width by adding 1
end; 

Changing the width / invalidating the control doesn't work for me (something changed with recent versions of RAD Studio?).

Anyway a similar, simple workaround along that line is:

procedure TForm1.FormResize(Sender: TObject);
begin
  GridPanel1.ControlCollection.BeginUpdate;
  GridPanel1.ControlCollection.EndUpdate;
end; 

I have had this error too, on several projects. I'm not sure how I solved this (it was on projects for my previous employer, I don't have access to this source code anymore). I think I had te redraw / refresh that parent frame or form on which the GridPanel was placed.

on the resize of the owner call GridPanel.Invalidate. I didn't test it. I hope it's work.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top