Lazarus
Programming => General => Topic started by: SaraT on February 20, 2020, 03:20:10 pm
-
Morning guys :) (8:15am)
The form option "BorderStyle" is bsNone and I would like to resize the form using a custom image on bottomright.
How can I do this?
I would be so thankful with your help.
-
What do you think of TStatusBar? (see Common Controls)
-
What do you think of TStatusBar? (see Common Controls)
Many thanks... I know that Aidex but I want to use a custom image :/
-
Good afternoon! (15:41) :)
My recomendation? Unless there are other reasons use one of the sizeable border styles.
Alternatively, you can use a TBitBtn, TSpeedButton or similar, or a TImage or similar, or a normal status bar (unsetting the left anchor and resizing if you want), etc.
Whatever you use, the basic mechanics of resizing a form w/ non-resizable border is to respond to the control's OnMouseDown, OnMouseMove and OnMouseUp events:- In the OnMouseDown handler you set a boolean "resizing" flag to True;
- In the OnMouseMove handler, check if "resizing" is set and, if so, compute the new bounds and resize the form;
- In the OnMouseUp handler, finally, reset the "resizing" flag to False
That's basically all there is to it.
All this, of course, means that whatever control you use must have those events. For your use case I would probably use either a TSpeedButton or a TImage anchored to the bottom-right of the form.
HTH!
-
You could capture the mouse events on the image and adjust the window size relative to the mouse movement.
UNTESTED Code! I think you also have to remember the original size of the window on click to make it work properly.
in TMyForm ...
DragStartX, DragStartY: Integer; // set default value at Create to: maxInt !!!
procedure TMyForm.MyImage1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
DragStartX:=x;
DragStartY:=y;
end;
procedure TMyForm.MyImage1MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var dx, dy: Integer;
begin
if (DragStartX=maxInt) or not (ssLeft in Shift) then Exit;
dx:=x-DragStartX;
dy:=y-DragStartY;
if (dx=0) and (dy=0) then Exit; // no change
self.Width:=self.Width+dx;
self.Height:=self.Height+dy;
end;
procedure TMyForm.MyImage1MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
DragStartX:=maxInt;
end;