Link to home
Create AccountLog in
Avatar of dudup
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(Sender: 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(Sender: 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.
Avatar of Mike Littlewood
Mike Littlewood
Flag of United Kingdom of Great Britain and Northern Ireland image

Should this need a couple more brackets to start with

if (X > (ClientWidth - 15)) Or (X < 15) Or (Y > (ClientHeight - 15)) then
Avatar of dudup
dudup

ASKER

That's not the problem :D

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;

erm nevermind the last message
ASKER CERTIFIED SOLUTION
Avatar of Mike Littlewood
Mike Littlewood
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Also it might be an idea to put a check in so that the user cannot make the window disappear.
Avatar of dudup

ASKER

Excellent mike !

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.
Hi,

Change to:

2: MoveWindow(Handle, Left + X, Top, Width - X, Height, TRUE);    // left

Regards, Geo
Too late... Hi Mike :-)
Avatar of dudup

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
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.
Heya Geo  :o)
Avatar of dudup

ASKER

Thanks mike :)
Glad I could help