Solved

Resizing Form

Posted on 2001-06-25
8
189 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

862 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now