Link to home
Start Free TrialLog in
Avatar of Mohamadi
MohamadiFlag for Iran, Islamic Republic of

asked on

Resizing Form

Hi
how can i tell a form to resize just in vertical,
and when mouse is over the corners, the cursor change to vertical arrow?

thanks in advance
Nima,
Avatar of z_darius
z_darius

all you need to do is this:

1. declare

const
  maxW=100;

2. initialize form's width in FormCreate method to the desired value (from the constant)

procedure TForm1.FormCreate(Sender: TObject);
begin
  width:=maxW;
end;

3. using FormResize method keep the width at constant's value

procedure TForm1.FormResize(Sender: TObject);
begin
  if (width > maxW) or (width < maxW)then
    width:=maxW;
end;
Avatar of StevenB
 You can also implement this at design time by using the forms Constraints property and setting MaxWidth and MinWidth the the same value.
Avatar of Mohamadi

ASKER

thanks,
but how can i tell the form to change the cursor to vertical arrow, not the slip one,

i saw this ability in MS Money 97, in the search form.

thanks agian
Nima,
One solution would be to do this:

1) Set the forms BorderStyle property to bsSingle.

2) Declare this constant in the interface section of the form's code:
  const
    DragRegion = 10;

3) Declare these variables in the form declaration:
  private
    fMouseDown : Boolean;
    fMouseDownY : Integer;
    fInitialHeight : Integer;

4) Add these event handlers to your form:

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  If (Y > (ClientHeight - DragRegion)) then begin
    fMouseDown := True;
    fInitialHeight := Height;
    fMouseDownY := Y;
  end;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  If (Y > (ClientHeight - DragRegion)) then Screen.Cursor := crSizeNS
  else Screen.Cursor := crDefault;
  If fMouseDown then begin
    Height := fInitialHeight + (Y-fMouseDownY);
  end;
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  fMouseDown := False;
end;




The full code from my test application unit is:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

const
  DragRegion = 10;

type
  TForm1 = class(TForm)
    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
  private
    fMouseDown : Boolean;
    fMouseDownY : Integer;
    fInitialHeight : Integer;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  If (Y > (ClientHeight - DragRegion)) then begin
    fMouseDown := True;
    fInitialHeight := Height;
    fMouseDownY := Y;
  end;
end;

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
  If (Y > (ClientHeight - DragRegion)) then Screen.Cursor := crSizeNS
  else Screen.Cursor := crDefault;
  If fMouseDown then begin
    Height := fInitialHeight + (Y-fMouseDownY);
  end;
end;

procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
  fMouseDown := False;
end;

end.



  There may be a neater solution that interfaces directly with the Windows API, but I couldn't find it after a brief look. This, however, achieves what you want I think.

  Steven.


Mohamadi,

I think it's time to award points, just in case you want have any kind of credibility for the future. Some folks (and I don't include myself) did some good job answering your questions. Now, show their answers were worth the effort.
ASKER CERTIFIED SOLUTION
Avatar of StevenB
StevenB

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks for your answer.
but as you said, there migth be a windows API function which changes the form's style.
if you find that i would be very happy to heare from you
my Email is Mohamadi@neda.net

thanks
with best regard
Nima,
 If I find anything I'll be sure to let you know.

  Cheers, Steven.