I have tried a number of ways to force the FormResize event to execute without sucess including SetWindowPos. The following code works very well when the form is resized with the mouse, but I also need to call this manually with code. I do not want the for开发者_StackOverflow中文版m to change in any way however.
procedure TFormMain.FormResize( Sender: TObject );
begin
dxDockPanelFolders1.Height := dxVertContainerDockSite1.Height div 3;
dxDockPanelFiles1.Height := dxVertContainerDockSite1.Height div 3;
dxDockPanelPreview1.Height := dxVertContainerDockSite1.Height div 3;
end;
I have not see anyway to accomplish this while searching the web.
I would use some indirection:
procedure TFormMain.UpdateDockPanelLayout;
begin
dxDockPanelFolders1.Height := dxVertContainerDockSite1.Height div 3;
dxDockPanelFiles1.Height := dxVertContainerDockSite1.Height div 3;
dxDockPanelPreview1.Height := dxVertContainerDockSite1.Height div 3;
end;
procedure TFormMain.FormResize(Sender: TObject);
begin
UpdateDockPanelLayout;
end;
Now you can call UpdateDockPanelLayout
directly from anywhere in your code.
I realise that you can call FormResize
and pass a Sender
but that solution somehow makes me feel dirty. Doing it as suggested above also allows you to name the method more specifically and not be so tightly coupled with the UI events that drive it.
Do you really need the event to fire, or is it enough if only the event handler is executed? If it is, simply do
FormResize(Self);
If you really need the event to fire, just do
Resize;
Uh, just call
FormResize(nil);
when you need to adjust the controls?
精彩评论