Solved

Resizing Form

Posted on 2001-06-25
8
188 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 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

12 Experts available now in Live!

Get 1:1 Help Now