Lazarus

Programming => General => Topic started by: SaraT on February 20, 2020, 03:20:10 pm

Title: Resize form using custom image
Post 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.
Title: Re: Resize form using custom image
Post by: Aidex on February 20, 2020, 03:32:42 pm
What do you think of TStatusBar? (see Common Controls)
Title: Re: Resize form using custom image
Post by: SaraT on February 20, 2020, 03:36:27 pm
What do you think of TStatusBar? (see Common Controls)
Many thanks... I know that Aidex but I want to use a custom image :/
Title: Re: Resize form using custom image
Post by: lucamar on February 20, 2020, 03:46:56 pm
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: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!
Title: Re: Resize form using custom image
Post by: Aidex on February 20, 2020, 03:55:49 pm
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.

Code: [Select]
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;
TinyPortal © 2005-2018