Solved

Resizing a form

Posted on 1998-02-18
15
342 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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

786 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