Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: OC DelGuy on February 26, 2021, 07:02:13 am

Title: Pictures in Forms
Post by: OC DelGuy 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.
Title: Re: Pictures in Forms
Post by: trev 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 :)
Title: Re: Pictures in Forms
Post by: OC DelGuy 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.
Title: Re: Pictures in Forms
Post by: trev 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.
Title: Re: Pictures in Forms
Post by: winni 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
Title: Re: Pictures in Forms
Post by: speter 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.
Title: Re: Pictures in Forms
Post by: winni 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