views:

685

answers:

5

Hi.

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.

+1  A: 

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.

birger
A: 

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

Ravaut123
+5  A: 

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.

onnodb
+1  A: 

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;

+1  A: 

I spent a considerable amount of time trying to fix a bug like this one. When I finally decided I needed to programmatically send a resize event to my components, I googled how to do that, landed here (it was the second hit), and two minutes later, Andreas' patch fixed the problem perfectly.

Way to go Andreas ... and StackOverflow!! :-)

Tom