Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: Refreshing TImage on a "Visible" form, not shown on the desktop


This question is answered.


Permlink Replies: 8 - Last Post: Mar 5, 2016 1:51 AM Last Post By: Lajos Juhasz
Trevor Hand

Posts: 58
Registered: 7/21/11
Refreshing TImage on a "Visible" form, not shown on the desktop  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 3, 2016 9:45 PM
I am creating a temporary form that contains a number of labels, and three TImage controls. After I have built up the final display, I capture the canvas of the temporary form to a bitmap and then write the bitmap to another form. However, the temporary form must not be seen by the user, so:

TemporaryForm.Left := -TemporaryForm.Width;

This puts the whole form off the desktop, but it is still "Visible". When I capture the temporary form's canvas, it contains all of my text and TWO of the image controls? If I move the temporary form to be visible on the desktop by setting TemporaryForm.Left := 0; all three images are visible. If I move the temporary form to be half on and half off the desktop, I get half the image in my capture....arghhhh!

The only difference I can see between the image controls is two are small, smaller than the form while the other one is set to the width and height of the temporary form, ie. it contains a background image upon which all the text and other images are written. How can I force the image control to paint its contents? I have tried calling refresh and invalidate on the temporary form (even on the TImage itself) and it still doesn't work. All of the labels are transparent, so they should not cover the image and hide it.

If I set the form to be double buffered, it DOES refresh the image, but the double buffering causes a lot of very weird effects, the text on the temporary form is actually scrolling each timer tick, the moved text is then captured and written to the form visible to the user. Double buffering captures part of the background of a completely different form from the application as part of the background...too hard to describe, and you wouldn't believe it either, but it does! Double buffering has a lot of problems.
Linden ROTH

Posts: 467
Registered: 11/3/11
Re: Refreshing TImage on a "Visible" form, not shown on the desktop
Helpful
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 4, 2016 1:09 AM   in response to: Trevor Hand in response to: Trevor Hand
Trevor Hand wrote:
I am creating a temporary form that contains a number of labels, and three TImage controls. After I have built up the final display, I capture the canvas of the temporary form to a bitmap and then write the bitmap to another form. However, the temporary form must not be seen by the user, so:

TemporaryForm.Left := -TemporaryForm.Width;

This puts the whole form off the desktop, but it is still "Visible". When I capture the temporary form's canvas, it contains all of my text and TWO of the image controls? If I move the temporary form to be visible on the desktop by setting TemporaryForm.Left := 0; all three images are visible. If I move the temporary form to be half on and half off the desktop, I get half the image in my capture....arghhhh!

The only difference I can see between the image controls is two are small, smaller than the form while the other one is set to the width and height of the temporary form, ie. it contains a background image upon which all the text and other images are written. How can I force the image control to paint its contents? I have tried calling refresh and invalidate on the temporary form (even on the TImage itself) and it still doesn't work. All of the labels are transparent, so they should not cover the image and hide it.

If I set the form to be double buffered, it DOES refresh the image, but the double buffering causes a lot of very weird effects, the text on the temporary form is actually scrolling each timer tick, the moved text is then captured and written to the form visible to the user. Double buffering captures part of the background of a completely different form from the application as part of the background...too hard to describe, and you wouldn't believe it either, but it does! Double buffering has a lot of problems.

try hiding it less

ie TemporaryForm.Left := -TemporaryForm.Width div 2;

and see if that has an effect

AND OR hide it with TemporaryForm.Left := 10000;

AND OR Hide it by using Z order (behind your real form)

just some Friday night kicking back ideas

--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"

Trevor Hand

Posts: 58
Registered: 7/21/11
Re: Refreshing TImage on a "Visible" form, not shown on the desktop  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 4, 2016 1:57 PM   in response to: Linden ROTH in response to: Linden ROTH
I will try Remy's suggestion, but I hadn't thought of moving it far to the right, maybe negative is something special...

I tried sitting it half on and half off...and I got only the visible half of the background image, really to be expected considering.

I had thought of putting it behind the visible form, which would work, but under some circumstances I need to hide the visible form, so I would have to keep the two forms tracking each other.

Just some Saturday morning things to try!


Linden ROTH wrote:
Trevor Hand wrote:
I am creating a temporary form that contains a number of labels, and three TImage controls. After I have built up the final display, I capture the canvas of the temporary form to a bitmap and then write the bitmap to another form. However, the temporary form must not be seen by the user, so:

TemporaryForm.Left := -TemporaryForm.Width;

This puts the whole form off the desktop, but it is still "Visible". When I capture the temporary form's canvas, it contains all of my text and TWO of the image controls? If I move the temporary form to be visible on the desktop by setting TemporaryForm.Left := 0; all three images are visible. If I move the temporary form to be half on and half off the desktop, I get half the image in my capture....arghhhh!

The only difference I can see between the image controls is two are small, smaller than the form while the other one is set to the width and height of the temporary form, ie. it contains a background image upon which all the text and other images are written. How can I force the image control to paint its contents? I have tried calling refresh and invalidate on the temporary form (even on the TImage itself) and it still doesn't work. All of the labels are transparent, so they should not cover the image and hide it.

If I set the form to be double buffered, it DOES refresh the image, but the double buffering causes a lot of very weird effects, the text on the temporary form is actually scrolling each timer tick, the moved text is then captured and written to the form visible to the user. Double buffering captures part of the background of a completely different form from the application as part of the background...too hard to describe, and you wouldn't believe it either, but it does! Double buffering has a lot of problems.

try hiding it less

ie TemporaryForm.Left := -TemporaryForm.Width div 2;

and see if that has an effect

AND OR hide it with TemporaryForm.Left := 10000;

AND OR Hide it by using Z order (behind your real form)

just some Friday night kicking back ideas

--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"

Trevor Hand

Posts: 58
Registered: 7/21/11
Re: Refreshing TImage on a "Visible" form, not shown on the desktop  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 4, 2016 3:00 PM   in response to: Trevor Hand in response to: Trevor Hand

try hiding it less

ie TemporaryForm.Left := -TemporaryForm.Width div 2;

and see if that has an effect

You see half of the image from the form, as you would probably expect given the problem. All the labels work, but it appears the image must be on the desktop. I guess a test would be to build a form off the desktop, then move it to the desktop and see if Windows paints it correctly. I am thinking it would, Windows probably knows when something is on a truly visible screen and so would invalidate at least part of the form and image and repaint it.


AND OR hide it with TemporaryForm.Left := 10000;

I have three monitors, so I set Left = 2000 and it appeared on my second monitor, and it worked (as expected). Set left to 10000 and none of it appeared, even on my third monitor, and it didn't work. So, being negative isn't a special case.

AND OR Hide it by using Z order (behind your real form)

I placed it's top and left to the same as the form being displayed to the user, but behind it. This works, as you would expect, but if I select an option not to show the display form to the user, the temporary form is visible, so I would have to handle the display of the temporary form and follow visibility, but as Remy's suggestion of AlphaBlend worked, I won't have to deal with this complication. If AlphaBlend hadn't worked, it would probably have been the only choice I would have left.

Hopefully the answers and suggestions are findable for people with a similar problem in the future.

Thanks for the input, always good to try different things.

just some Friday night kicking back ideas

--
Linden
"Mango" was Cool but "Wasabi" was Hotter but remember it's all in the "source"
Lajos Juhasz

Posts: 801
Registered: 3/14/14
Re: Refreshing TImage on a "Visible" form, not shown on the desktop  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 5, 2016 1:51 AM   in response to: Trevor Hand in response to: Trevor Hand
Trevor Hand wrote:

but as Remy's suggestion of AlphaBlend worked, I won't have to deal
with this complication. If AlphaBlend hadn't worked, it would
probably have been the only choice I would have left.

Hopefully the answers and suggestions are findable for people with a
similar problem in the future.

Thanks for the input, always good to try different things.

Thank you for the information. I've faced similair problem in the past.
Now I just have to find some spare time to use AlphaBlend to avoid
flickering on the screen.
Remy Lebeau (Te...


Posts: 9,447
Registered: 12/23/01
Re: Refreshing TImage on a "Visible" form, not shown on the desktop
Correct
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 4, 2016 10:03 AM   in response to: Trevor Hand in response to: Trevor Hand
Trevor wrote:

If I move the temporary form to be visible on the desktop by setting
TemporaryForm.Left := 0; all three images are visible. If I move the
temporary form to be half on and half off the desktop, I get half the
image in my capture....arghhhh!

I would suggest leaving the Form fully visible on the screen (Left >= 0),
but set its AlphaBlend to True and its AlphaBlendValue to 1. This way, the
user cannot see it, but the OS can.

--
Remy Lebeau (TeamB)
Trevor Hand

Posts: 58
Registered: 7/21/11
Re: Refreshing TImage on a "Visible" form, not shown on the desktop  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 4, 2016 1:52 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hey, now that's an idea!

Funny though how some things render and some don't, I would have thought it is all or nothing.

As for the effect I saw when setting the form to DoubleBuffered, it only happened with particular values. Most of the time it worked perfectly, then I just happened to test one layout and the whole thing went nuts!

I will give it a try....let you know.

Remy Lebeau (TeamB) wrote:
Trevor wrote:

If I move the temporary form to be visible on the desktop by setting
TemporaryForm.Left := 0; all three images are visible. If I move the
temporary form to be half on and half off the desktop, I get half the
image in my capture....arghhhh!

I would suggest leaving the Form fully visible on the screen (Left >= 0),
but set its AlphaBlend to True and its AlphaBlendValue to 1. This way, the
user cannot see it, but the OS can.

--
Remy Lebeau (TeamB)
Trevor Hand

Posts: 58
Registered: 7/21/11
Re: Refreshing TImage on a "Visible" form, not shown on the desktop  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 4, 2016 2:45 PM   in response to: Trevor Hand in response to: Trevor Hand
It worked! In the end a very simple solution, but a bit of "thinking outside the box" I guess.

Thanks for that Remy, I can get some of my weekend back :-)

Trevor
Trevor Hand wrote:
Hey, now that's an idea!

Funny though how some things render and some don't, I would have thought it is all or nothing.

As for the effect I saw when setting the form to DoubleBuffered, it only happened with particular values. Most of the time it worked perfectly, then I just happened to test one layout and the whole thing went nuts!

I will give it a try....let you know.

Remy Lebeau (TeamB) wrote:
Trevor wrote:

If I move the temporary form to be visible on the desktop by setting
TemporaryForm.Left := 0; all three images are visible. If I move the
temporary form to be half on and half off the desktop, I get half the
image in my capture....arghhhh!

I would suggest leaving the Form fully visible on the screen (Left >= 0),
but set its AlphaBlend to True and its AlphaBlendValue to 1. This way, the
user cannot see it, but the OS can.

--
Remy Lebeau (TeamB)
Trevor Hand

Posts: 58
Registered: 7/21/11
Re: Refreshing TImage on a "Visible" form, not shown on the desktop  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Mar 4, 2016 3:21 PM   in response to: Remy Lebeau (Te... in response to: Remy Lebeau (Te...
Hahahaha! I just figured out that the form is not "visible" but you can still move the mouse over it! So I have now moved it to sit under the display form, so normally it is visible but hidden. When I "hide" the display form, the transparent temporary form is now "visible" but cannot be seen, so if you have any shortcuts "under" this transparent form, you can't click them! This won't be a real problem for us as we have a special image in this area of the desktop and do not want the user to place anything in this area.

It does look rather amusing that you move the mouse over the desktop and it suddenly disappears (the temporary form's cursor is crNone). If I set a cursor, you can move over the shortcuts, but they are unresponsive! A bit of a trap if you aren't aware.

Maybe an April fool's joke? Create a transparent form that covers the desktop, suddenly all of your shortcuts stop working!


Remy Lebeau (TeamB) wrote:
Trevor wrote:

If I move the temporary form to be visible on the desktop by setting
TemporaryForm.Left := 0; all three images are visible. If I move the
temporary form to be half on and half off the desktop, I get half the
image in my capture....arghhhh!

I would suggest leaving the Form fully visible on the screen (Left >= 0),
but set its AlphaBlend to True and its AlphaBlendValue to 1. This way, the
user cannot see it, but the OS can.

--
Remy Lebeau (TeamB)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02