Recent

Author Topic: Pictures in Forms  (Read 1417 times)

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
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.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • 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 :)

OC DelGuy

  • Full Member
  • ***
  • Posts: 121
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.2.4
Date: 24 SEP 2022
FPC Version: 3.2.2
Revision: Lazarus_2_2_4
x86_64-win64-win32/win64

trev

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2020
  • 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.

winni

  • Hero Member
  • *****
  • Posts: 3197
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

  • Sr. Member
  • ****
  • Posts: 345
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. :)

winni

  • Hero Member
  • *****
  • Posts: 3197
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