ronit051397
asked on
Resizing a form
Is there a way to resize a form only vertically?
ASKER
I need a 'BeforeResize' event, but there isn't any.
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.
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.
ASKER
Actually, you are right, but I don't want the user to see the resizing cursor. Any other suggestions?
Maybe try to replace Cursor crSizeWE with crDefault
ASKER
The form also moves when i try to resize from the left. Is there an elegant solution?
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
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
ASKER
It acts the same. I still see the mouse sizing cursor.
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
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
ASKER
No, it doesn't work properly according to the following code:
procedure TForm1.FormMouseMove(Sende r: TObject; Shift: TShiftState; X,
Y: Integer);
begin
if (x=width) or (x=0) then
borderstyle:=bsSingle
else
borderstyle:=bsSizeable;
end;
procedure TForm1.FormMouseMove(Sende
Y: Integer);
begin
if (x=width) or (x=0) then
borderstyle:=bsSingle
else
borderstyle:=bsSizeable;
end;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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;
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;
Dear ronit,
I am working on it. (this is extremely flickery)
Igor
I am working on it. (this is extremely flickery)
Igor
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+Widt h+5, Msg.XPos) then
Msg.XPos := Msg.XPos - 10;
inherited;
end;
Bye
Igor
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+Widt
Msg.XPos := Msg.XPos - 10;
inherited;
end;
Bye
Igor
ASKER
Cheers.
Igor