dudup
asked on
Resizing manually
I tried to make a code to handle window (form) resizing :
I set the Form Style to bsNone.
In the onMouseDown event :
procedure TForm1.FormMouseDown(Sende r: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
if (X > ClientWidth - 15) Or (X < 15) Or (Y > ClientHeight - 15) then
begin
GoResize := TRUE;
if (X > ClientWidth - 15) then
begin
ResizeMode := 1; // to right
Screen.Cursor := crSizeWE;
end
else if (X < 15) then
begin
ResizeMode := 2; // to left
Screen.Cursor := crSizeWE;
end
else begin
ResizeMode := 3; // to bottom
Screen.Cursor := crSizeNS;
end;
end;
end;
Then I do resize in onMouseMove event :
procedure TForm1.FormMouseMove(Sende r: TObject; Shift: TShiftState; X, Y: Integer);
begin
if GoResize then
begin
Case ResizeMode of
1: MoveWindow(Handle, Left, Top, X, Height, TRUE); // right
2: MoveWindow(Handle, X, Top, Width, Height, TRUE); // left
3: MoveWindow(Handle, Left, Top, Width, Y, TRUE); // bottom
end;
end;
end;
The problem is, "left" resizing does not work. Anyone know what is wrong here ?
Thanks.
I set the Form Style to bsNone.
In the onMouseDown event :
procedure TForm1.FormMouseDown(Sende
begin
if (X > ClientWidth - 15) Or (X < 15) Or (Y > ClientHeight - 15) then
begin
GoResize := TRUE;
if (X > ClientWidth - 15) then
begin
ResizeMode := 1; // to right
Screen.Cursor := crSizeWE;
end
else if (X < 15) then
begin
ResizeMode := 2; // to left
Screen.Cursor := crSizeWE;
end
else begin
ResizeMode := 3; // to bottom
Screen.Cursor := crSizeNS;
end;
end;
end;
Then I do resize in onMouseMove event :
procedure TForm1.FormMouseMove(Sende
begin
if GoResize then
begin
Case ResizeMode of
1: MoveWindow(Handle, Left, Top, X, Height, TRUE); // right
2: MoveWindow(Handle, X, Top, Width, Height, TRUE); // left
3: MoveWindow(Handle, Left, Top, Width, Y, TRUE); // bottom
end;
end;
end;
The problem is, "left" resizing does not work. Anyone know what is wrong here ?
Thanks.
ASKER
That's not the problem :D
The problem is this :
2: MoveWindow(Handle, X, Top, Width, Height, TRUE); // left
The problem is this :
2: MoveWindow(Handle, X, Top, Width, Height, TRUE); // left
Is your code actually getting to
else begin
ResizeMode := 3; // to bottom
Screen.Cursor := crSizeNS;
end;
else begin
ResizeMode := 3; // to bottom
Screen.Cursor := crSizeNS;
end;
erm nevermind the last message
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Also it might be an idea to put a check in so that the user cannot make the window disappear.
ASKER
Excellent mike !
Why Left + X and Width - X ???? How did you come with that ?
Why Left + X and Width - X ???? How did you come with that ?
Well you are moving the Left position based on the value of X, but to take this into account you need to reduce the width accordingly.
Doing it from the right is easier as you are making your X positioin equal to the width and not having to move the left position based on this.
Doing it from the right is easier as you are making your X positioin equal to the width and not having to move the left position based on this.
Hi,
Change to:
2: MoveWindow(Handle, Left + X, Top, Width - X, Height, TRUE); // left
Regards, Geo
Change to:
2: MoveWindow(Handle, Left + X, Top, Width - X, Height, TRUE); // left
Regards, Geo
Too late... Hi Mike :-)
ASKER
Mike, I increased the score because I want to ask you about this :
"Also it might be an idea to put a check in so that the user cannot make the window disappear."
How can that happen ?
:D
"Also it might be an idea to put a check in so that the user cannot make the window disappear."
How can that happen ?
:D
Well I seemed to be able to resize the window down to nothing. Does this not happen to you?
I would set the constraints of the form to have a MinHeight and MinWidth of whatever you feel is small enough for the resize.
I would set the constraints of the form to have a MinHeight and MinWidth of whatever you feel is small enough for the resize.
Heya Geo :o)
ASKER
Thanks mike :)
Glad I could help
if (X > (ClientWidth - 15)) Or (X < 15) Or (Y > (ClientHeight - 15)) then