Solved

Resizing a form

Posted on 1998-02-18
15
350 Views
Last Modified: 2010-04-04
Is there a way to resize a form only vertically?
0
Comment
Question by:ronit051397
  • 7
  • 6
  • 2
15 Comments
 
LVL 5

Expert Comment

by:inter
ID: 1359512
Does not playing with Top and Height solves the problem?

Igor
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1359513
I need a 'BeforeResize' event, but there isn't any.
0
 

Expert Comment

by:nejck
ID: 1359514
I suppose that you want to prevent user to
resize form width, but still let him to resize height.

You can do that with setting Form.Width:=400
on form resize event which will prevent form to change width.
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 5

Author Comment

by:ronit051397
ID: 1359515
Actually, you are right, but I don't want the user to see the resizing cursor. Any other suggestions?
0
 

Expert Comment

by:nejck
ID: 1359516
Maybe try to replace Cursor crSizeWE with crDefault
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1359517
The form also moves when i try to resize from the left. Is there an elegant solution?
0
 
LVL 5

Expert Comment

by:inter
ID: 1359518
dear ronit,

There is a beforeresize event equivalent, but you must capture a message. I am sure this is not problem for you. You can prevent user from resizing in any way you want. Them message is as follows:

The WM_WINDOWPOSCHANGING message is sent to a window whose size, position, or place in the Z order is about to change as a result of a call to the SetWindowPos function or another window-management function.

WM_WINDOWPOSCHANGING  
lpwp = (LPWINDOWPOS) lParam; // points to size and position data
 

lpwp Value of lParam. Points to a WINDOWPOS structure that contains information about the window's new size and position.

If you modify the WINDOWPOS such that only vertical position parameters changed then you can prevent horizontal resizing and pos changing.

May it help, please notify,

Igor

 


0
 
LVL 5

Author Comment

by:ronit051397
ID: 1359519
It acts the same. I still see the mouse sizing cursor.
0
 
LVL 5

Expert Comment

by:inter
ID: 1359520
This is not proper way but,

what about setting BorderStyle to bsSingle if the mouse cursor is
on the lower or upper edge of the form and bsSizeable else where?

If this trick works(or suffice) please notify

Sincerely,
Igor
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1359521
No, it doesn't work properly according to the following code:

procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin
if (x=width) or (x=0) then
  borderstyle:=bsSingle
else
  borderstyle:=bsSizeable;
end;

0
 
LVL 5

Accepted Solution

by:
inter earned 100 total points
ID: 1359522
Dear ronit,

This may solve your problem, (with verry little flickering). I hope you use Delphi 2.0+. I can not test it on Delphi 1.0.

Igor


procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.OnMessage := AppMessage;
end;

procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
var
  R1, R2: TRect;
  P: TPoint;
var
  x, y: integer;
type
  PPoints = ^TPoints;
  TPoints = packed record
    x, y: smallint;
  end;
begin
  Handled := false;
  if Msg.Message = WM_NCMOUSEMOVE then
  begin
    x := PPoints(@msg.lparam)^.x;
    y := PPoints(@msg.lparam)^.y;
    // we'd better check for a rectangle rather
    // than single point
    R1 := Rect(Left - 5, Top - 5, Left + 5, Top + Height + 5);
    R2 := Rect(Left + Width - 5, Top - 5, Left + Width + 5, Top + Height + 5);
    P := Point(x, y);
    //prevent flickering
    LockWindowUpdate(Handle);
    if (PtInRect(R1, P)) or (PtInRect(R2, P)) then
      borderstyle := bsSingle
    else
      borderstyle := bsSizeable;
    LockWindowUpdate(Handle);
  end;
end;
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1359523
The flickering is too bothering. This code does the same as yours, but on a more proper way. I think we should use some function that has something to do with the mouse capture. Do you have any suggestions?

type
  TForm1 = class(TForm)
  private
    procedure WMHotSpot(var Message: TMessage); message WM_NCHITTEST;
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}
procedure TForm1.WMHotSpot(var Message: TMessage);
begin
  if (DefWindowProc(handle, WM_NCHITTEST, message.WParam, message.LParam)=HTLEFT) or
  (DefWindowProc(handle, WM_NCHITTEST, message.WParam, message.LParam)=HTRIGHT) then
    borderstyle:=bssingle
  else
    borderstyle:=bsSizeable;
  inherited;
end;

0
 
LVL 5

Expert Comment

by:inter
ID: 1359524
Dear ronit,

I am working on it. (this is extremely flickery)

Igor
0
 
LVL 5

Expert Comment

by:inter
ID: 1359525
THIS IS IT RONIT


type
  TForm1 = class(TForm)
  private
    { Private declarations }
  public
    procedure WMNCHitTest(var Msg : TWMNCHitTest); message WM_NCHitTest;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WMNCHitTest(var Msg : TWMNCHitTest);
  function InR(lo,hi,x : integer):boolean;
  begin
    Result := (lo < x) and (x < hi);
  end;
begin
  if InR(Left-5,Left+5, Msg.XPos) then
    Msg.XPos := Msg.XPos + 10
  else if InR(Left+Width-5,Left+Width+5, Msg.XPos) then
    Msg.XPos := Msg.XPos - 10;
  inherited;
end;


Bye
Igor
0
 
LVL 5

Author Comment

by:ronit051397
ID: 1359526
Cheers.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

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…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

839 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