Fórum Mudar tamanho do TPanel no arrastar do mouse #559095
08/07/2016
0
Victor Mendes
Curtir tópico
+ 0Posts
08/07/2016
Natanael Ferreira
Para ver o seu funcionamento:
- Solte um Panel e mande alinhar a esquerda,
- Um Splitter
- E outro Panel com alinhamento Client.
Basta executar, passar o mouse sobre o mesmo para ver o funcionamento.
Gostei + 0
08/07/2016
Victor Mendes
Gostei + 0
04/01/2023
Paulo Bornhiati
Como procurei e não encontrei nada que possibilitasse aumentar ou diminuir o Panel em tempo de execução sem usar o splitter, acabei fazendo o meu.
Como pretendia fazer para outros componentes, TImage por exemplo, criei uma nova procedure MouseMove e chamo ela de cada um dos componentes que pretendo permitir a alteração.
Para funcionar, crie duas variáveis globais, x_ant ey_ant do tipo Integer, estas variáveis serão usadas para determinar se o mouse foi movido acima ou abaixo, apenas para referência (se alguém tiver ideia melhor aceito sugestões).
O funcionamento é simples, posicione o mouse próximo ao canto superior direito e pressione e mantenha pressionado o ctrl e mova o mouse.
Na mesma procedure, consigo controlar o posicionamento da TLabel, TImage ou TPanel, podendo mover na tela.
Eu salvo as informações em um INI, e recupero sempre que necessário reiniciar a aplicação, mantendo assim o tamanho e posições deixadas anteriormente.
Espero que ajude mais alguém que sofreu assim como eu para conseguir algo.
var x_ant,y_ant:Integer;
procedure TForm1.MouseMove2(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
var Pos: TPoint;
begin
if (Sender is Tpanel) and (ssCtrl in Shift) then
begin
Pos := TPanel(Sender).ScreenToClient(Mouse.CursorPos);
if x_ant<Mouse.CursorPos.X then
if ((Pos.X>=TPanel(Sender).Width-20) and (Pos.X<=TPanel(Sender).Width+20)) then
TPanel(Sender).Width:=TPanel(Sender).Width+1;
if (x_ant>Mouse.CursorPos.X) then
if ((Pos.X>=TPanel(Sender).Width-20) and (Pos.X<=TPanel(Sender).Width+20)) then
TPanel(Sender).Width:=TPanel(Sender).Width-1;
if y_ant<Mouse.CursorPos.Y then
if ((Pos.X>=TPanel(Sender).Width-20) and (Pos.X<=TPanel(Sender).Width+20)) then
begin
TPanel(Sender).top:=TPanel(Sender).top+1;
TPanel(Sender).Height:=TPanel(Sender).Height-1;
end;
if (y_ant>Mouse.CursorPos.Y) then
if ((Pos.X>=TPanel(Sender).Width-20) and (Pos.X<=TPanel(Sender).Width+20)) then
begin
TPanel(Sender).top:=TPanel(Sender).top-1;
TPanel(Sender).Height:=TPanel(Sender).Height+1;
end;
end
else
begin
lbl1.caption := IntToStr(Mouse.CursorPos.X);
lbl2.caption := IntToStr(Mouse.CursorPos.Y);
if Sender is TLabel then
begin
TLabel(Sender).Top := TLabel(Sender).Top + Y - PosMouseY;
TLabel(Sender).Left:= TLabel(Sender).Left + X - PosMouseX;
end
else if Sender is TPanel then
begin
TPanel(Sender).Top := TPanel(Sender).Top + Y - PosMouseY;
TPanel(Sender).Left:= TPanel(Sender).Left + X - PosMouseX;
end else if Sender is TImage then
begin
TImage(Sender).Top := TImage(Sender).Top + Y - PosMouseY;
TImage(Sender).Left:= TImage(Sender).Left + X - PosMouseX;
end
end;
x_ant:=Mouse.CursorPos.X;
y_ant:=Mouse.CursorPos.Y;
end;
Gostei + 0
05/01/2023
Arthur Heinrich
type
TForm1 = class(TForm)
Panel1: TPanel;
procedure Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure FormCreate(Sender: TObject);
procedure Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
procedure Panel1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
{ Private declarations }
public
{ Public declarations }
ResizePanel : TPanel;
ResizeStart, ResizeInitialSize : TPoint;
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Panel1MouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
var
P : TPanel;
begin
P:=(Sender as TPanel);
if ((X>p.Width-10) and (Y>P.Height-10) and (Mouse.Capture>0))
then
begin
ResizePanel:=P;
ResizeStart:=Point(X,Y);
ResizeInitialSize:=Point(P.Width,P.Height);
end;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
ResizePanel:=nil;
end;
procedure TForm1.Panel1MouseMove(Sender: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if Assigned(ResizePanel)
then
begin
ResizePanel.Width:=ResizeInitialSize.x+X-ResizeStart.x;
ResizePanel.Height:=ResizeInitialSize.y+Y-ResizeStart.y;
end;
end;
procedure TForm1.Panel1MouseUp(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
ReleaseCapture;
ResizePanel:=nil;
end;
Gostei + 0
Clique aqui para fazer login e interagir na Comunidade :)