Bookstore

Recent

Author Topic: Resize form using custom image  (Read 170 times)

SaraT

  • Jr. Member
  • **
  • Posts: 81
  • A little student
Resize form using custom image
« 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.

Aidex

  • New Member
  • *
  • Posts: 31
Re: Resize form using custom image
« Reply #1 on: February 20, 2020, 03:32:42 pm »
What do you think of TStatusBar? (see Common Controls)

SaraT

  • Jr. Member
  • **
  • Posts: 81
  • A little student
Re: Resize form using custom image
« Reply #2 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 :/

lucamar

  • Hero Member
  • *****
  • Posts: 2579
Re: Resize form using custom image
« Reply #3 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:
  • 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!
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.6/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Aidex

  • New Member
  • *
  • Posts: 31
Re: Resize form using custom image
« Reply #4 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;