Solved

Resizing a form

Posted on 1998-02-18
15
332 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
 
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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
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.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

19 Experts available now in Live!

Get 1:1 Help Now