Solved

Resizing a form

Posted on 1998-02-18
15
355 Views
Last Modified: 2010-04-04
Is there a way to resize a form only vertically?
0
Comment
Question by:ronit051397
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…

726 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