Recent

Author Topic: Pictures in Forms  (Read 579 times)

OC DelGuy

  • New Member
  • *
  • Posts: 30
Pictures in Forms
« on: February 26, 2021, 07:02:13 am »
How can I set the background of a form into a user specified image?  I'd also like to know how to set an initial background image on a form.  I'd like to put my logo on there first.
I'm making a program in which I'd like the user to be able to select a background image to be displayed under the other controls of the form.  Much like the desktop image on Windows.  Only, in this case, it's a "Form Desktop".   ;D
Is that allowed?  I don't see a property in the Lazarus Object Inspector.
Free Pascal Lazarus Version #: 2.0.10
Date: 07 JUL 2020
FPC Version: 3.2.0
SVN Revision: 63526
x86_64-win64-win32/win64

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1386
  • Former Delphi 1-7, 10.2 User
Re: Pictures in Forms
« Reply #1 on: February 26, 2021, 07:22:20 am »
Drop a TImage on your form; set to fill the client area; load image; centre image; done :)
Lazarus 2.1 r65019 FPC 3.3.1 r49223 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r65019 FPC 3.3.1 r49223 macOS 11.2.3 aarch64 Xcode 12.4
Lazarus 2.1 r61574 FPC 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 FPC 3.2.0 Win10 Parallels VM

OC DelGuy

  • New Member
  • *
  • Posts: 30
Re: Pictures in Forms
« Reply #2 on: February 27, 2021, 09:53:49 pm »
Drop a TImage on your form; set to fill the client area; load image; center image; done :)

Thanks Trev.  I did think of that, and I realize now that I didn't include this in my OP, but I ran into the problem that when I do things like Canvas.Ellipse, Canvas.Line or Canvas.Rectangle and other Canvas commands, they end up under the TImage and can't be seen.

I'm displaying some charts on the screen that show the user's progress toward a goal.  The background image is the incentive they see every time they record their progress.  I was hoping to make that a background and the user's profile pic a foreground displayed with the charts.
Free Pascal Lazarus Version #: 2.0.10
Date: 07 JUL 2020
FPC Version: 3.2.0
SVN Revision: 63526
x86_64-win64-win32/win64

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 1386
  • Former Delphi 1-7, 10.2 User
Re: Pictures in Forms
« Reply #3 on: February 27, 2021, 10:52:40 pm »
Are you drawing outside the onpaint event? In the absence of code that as far as I can speculate.

TImage is best used if you need a persistent image.
Lazarus 2.1 r65019 FPC 3.3.1 r49223 macOS 10.14.6 Xcode 11.3.1
Lazarus 2.1 r65019 FPC 3.3.1 r49223 macOS 11.2.3 aarch64 Xcode 12.4
Lazarus 2.1 r61574 FPC 3.3.1 r42318 FreeBSD 12.1 amd64 VMware VM
Lazarus 2.1 r61574 FPC 3.0.4 Ubuntu 20.04 Parallels VM
Lazarus 2.0.10 FPC 3.2.0 Win10 Parallels VM

winni

  • Hero Member
  • *****
  • Posts: 2290
Re: Pictures in Forms
« Reply #4 on: February 28, 2021, 12:11:05 am »
Hi!

On an TImage.canvas  you are allowed to paint in every situation.
On all other canvas you have to paint in the OnPaint event.

For your needs:
Make an invisible Bitmap of the BackGround.

If something  changes in your data:

in the TForm1.OnPaint event:
copy the background to the Form.canvas
draw your data on top of the Form.canvas.

Don't forget to destroy your Background-bitmap on closing the app.

Winni

speter

  • Full Member
  • ***
  • Posts: 184
Re: Pictures in Forms
« Reply #5 on: February 28, 2021, 12:13:52 am »
... I ran into the problem that when I do things like Canvas.Ellipse, Canvas.Line or Canvas.Rectangle and other Canvas commands, they end up under the TImage and can't be seen.
Consider putting a paintbox (tpaintbox) on your form ("above" the Timage) and draw on the paintbox's canvas, instead of the form's canvas.

cheers
S.
I climbed mighty mountains, and saw that they were actually tiny foothills. :)

Laz 2.0.10 / FPC 3.2.0 / Windows 10 (64bit)

winni

  • Hero Member
  • *****
  • Posts: 2290
Re: Pictures in Forms
« Reply #6 on: February 28, 2021, 12:24:04 am »
... I ran into the problem that when I do things like Canvas.Ellipse, Canvas.Line or Canvas.Rectangle and other Canvas commands, they end up under the TImage and can't be seen.
Consider putting a paintbox (tpaintbox) on your form ("above" the Timage) and draw on the paintbox's canvas, instead of the form's canvas.

cheers
S.

Hi!

????

Take a Form with a canvas.
Put an Image with a canvas on top.
Put a paintBox with a  a canvas on top of the image with a canvas on top of the form with a canvas????

For whatever reasons??

One canvas is enough.
If you prefer a persistent bitmap like in the Image it has advantages.

As I showed above; hold your background in a (invisble) bitmap.
That is the whole trick.

Winni

 

TinyPortal © 2005-2018