Solved

Resizing Form

Posted on 2001-06-25
8
191 Views
Last Modified: 2010-04-06
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,
0
Comment
Question by:Mohamadi
  • 4
  • 2
  • 2
8 Comments
 
LVL 1

Expert Comment

by:z_darius
ID: 6226117
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;
0
 
LVL 4

Expert Comment

by:StevenB
ID: 6226415
 You can also implement this at design time by using the forms Constraints property and setting MaxWidth and MinWidth the the same value.
0
 

Author Comment

by:Mohamadi
ID: 6229457
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,
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 4

Expert Comment

by:StevenB
ID: 6229582
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.


0
 
LVL 1

Expert Comment

by:z_darius
ID: 6233583
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.
0
 
LVL 4

Accepted Solution

by:
StevenB earned 10 total points
ID: 6233598
 Mohamadi has a good grading record, I'm sure he's just not available, or is checking the suggested solutions.
0
 

Author Comment

by:Mohamadi
ID: 6233643
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,
0
 
LVL 4

Expert Comment

by:StevenB
ID: 6233649
 If I find anything I'll be sure to let you know.

  Cheers, Steven.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question