Centralizar um panel no form
Pessoal estou tentando centralizar um panel no meu form ja tentei de um monte de jeito mas nunca dá certo ,alguém sabe como posso fazer isso?
Códigos tentados:
1 ------------Panel1.Left := (Self.Width - Panel1.Width) div 2;
------------Panel1.Top := (Self.Height - Panel1.Height) div 2;
2 ------------APanel.Left := (AForm.ClientWidth div 2) - (APanel.Width div 2);
------------ APanel.Top := (AForm.ClientHeight div 2) - (APanel.Height div 2);
3------------panel1.top := (self.Height div 2) - (panel1.height div 2);
------------panel1.left := (self.Width div 2) - (panel1.width div 2);
Códigos tentados:
1 ------------Panel1.Left := (Self.Width - Panel1.Width) div 2;
------------Panel1.Top := (Self.Height - Panel1.Height) div 2;
2 ------------APanel.Left := (AForm.ClientWidth div 2) - (APanel.Width div 2);
------------ APanel.Top := (AForm.ClientHeight div 2) - (APanel.Height div 2);
3------------panel1.top := (self.Height div 2) - (panel1.height div 2);
------------panel1.left := (self.Width div 2) - (panel1.width div 2);
Wanderson Cardoso
Curtidas 0
Melhor post
Natanael Ferreira
25/05/2021
Teste essa procedure:
Exemplo de uso, no evento OnResize do form:
Procedure CentralizarPanel(AForm: TForm; APanel: TPanel); begin APanel.Left := (AForm.ClientWidth div 2) - (APanel.Width div 2); APanel.Top := (AForm.ClientHeight div 2) - (APanel.Height div 2); APanel.Update; AForm.Update; end;
Exemplo de uso, no evento OnResize do form:
CentralizarPanel(Self, Panel1);
GOSTEI 2
Mais Respostas
Wanderson Cardoso
25/05/2021
Teste essa procedure:
Exemplo de uso, no evento OnResize do form:
Procedure CentralizarPanel(AForm: TForm; APanel: TPanel); begin APanel.Left := (AForm.ClientWidth div 2) - (APanel.Width div 2); APanel.Top := (AForm.ClientHeight div 2) - (APanel.Height div 2); APanel.Update; AForm.Update; end;
Exemplo de uso, no evento OnResize do form:
CentralizarPanel(Self, Panel1);
Debugando ele centralizou e depois quando chega na sengunda linha dessa procedure ele da 'access violation'
Mas valeu pela dica!
Todo conhecimento e bom!
GOSTEI 0
Wanderson Cardoso
25/05/2021
ops! erro meu!
Tava chamando de um form que não foi estanciado!
Agora funcionou valeu
Tava chamando de um form que não foi estanciado!
Agora funcionou valeu
GOSTEI 0