Solved

Resizing a form

Posted on 1998-02-18
15
364 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
Industry Leaders: 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

Industry Leaders: 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!

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…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month6 days, 4 hours left to enroll

626 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