Delphi TImage32 - how to make a component invisible if the image is not loaded?

If you place a regular TImage component on a form or panel on top of other components, it will be invisible at run time until the image is loaded. So other things beneath him are visible.

But TImage32 will color the gray square by default.

How to make it invisible, leaving the parameter: .Visible: = True; if the image is not uploaded?
(I still need events working on the component, like OnClick ...)

Yes, this is a duplicate question, BUT the link to the solution from the previous topic has died. :(

+1
source share
2 answers

As long as I still have access to messages in the newsgroups, I don’t know how the topic identifier relates to the topic name (that’s all I have). However, based on a search in a newsgroup, I found several places where TImage32Ex was mentioned. I assume that this component (which is not part of the main library) was somehow part of the solution.

So, while the expansion pack from which this component comes from is no longer supported, let’s dig deeper into what it did.

First, I have to say that TImage32 will always draw (copy) the contents of its buffer onto the display. This means that any graphics behind this component will still be overwritten.

The three of TImage32Ex is to get the contents of the parents and paste it into the buffer.

With adaptations, the code looks like this:

var P: TPoint; SaveIndex: Integer; begin SaveIndex := SaveDC(Buffer.Handle); try GetViewportOrgEx(Buffer.Handle, P); SetViewportOrgEx(Buffer.Handle, PX - Left, PY - Top, nil); IntersectClipRect(Buffer.Handle, 0, 0, Parent.ClientWidth, Parent.ClientHeight); Parent.Perform(WM_ERASEBKGND, Buffer.Handle, 0); Parent.Perform(WM_PAINT, Buffer.Handle, 0); finally RestoreDC(Buffer.Handle, SaveIndex); end; end; 

The above code draws (WM_PAINT) the parent content into the buffer.

For example, if you want the TPaintBox32 instance called PaintBox32 to be transparent, simply add the following code to the PaintBuffer handler:

 procedure TForm3.PaintBox32PaintBuffer(Sender: TObject); var P: TPoint; SaveIndex: Integer; begin SaveIndex := SaveDC(PaintBox32.Buffer.Handle); try GetViewportOrgEx(PaintBox32.Buffer.Handle, P); SetViewportOrgEx(PaintBox32.Buffer.Handle, PX - PaintBox32.Left, PY - PaintBox32.Top, nil); IntersectClipRect(PaintBox32.Buffer.Handle, 0, 0, PaintBox32.Parent.ClientWidth, PaintBox32.Parent.ClientHeight); PaintBox32.Parent.Perform(WM_ERASEBKGND, PaintBox32.Buffer.Handle, 0); PaintBox32.Parent.Perform(WM_PAINT, PaintBox32.Buffer.Handle, 0); finally RestoreDC(PaintBox32.Buffer.Handle, SaveIndex); end; end; 

Note. Although this works mostly, it may not properly capture the parent controls. This is especially true for descendants of TWinControl. Although there are solutions to cover this scenario, it’s much harder to cover this in every detail (for example, the blinking cursor of the underlying TEdit instance)

+1
source

I use a timer to mask the progress bar and shape it.

What I am doing is loading a png with transparent parts and then putting it on top of the progress bar.

I think this should achieve your goal. Put transparent png in your timeline.

Cheers, E.

0
source

Source: https://habr.com/ru/post/918941/


All Articles