Make a control transparent - delphi

Is there any way to make a control transparent like button, edit, panel or etc...? I mean something like opacity or alpha blend that we have in form property.

Some components have the transparent property. In others you can choose 'none' as the color property. It differs from component to component, but not all components can be made transparent by changing a property.
You should try googling Delphi transparent components, there are downloadable components and tricks you can do to make existing components transparent.

Take a look at the Win32 windows styles, especially WS_TRANSPARENT (or WS_EX_TRANSPARENT).

Applying transparency on a child control can be done very easily using old-fashioned regions and the SetWindowRgn() function.
Applying alpha blending on a child control, on the other hand, is very difficult to do prior to Windows 8. It involves painting the parent window to a bitmap first, then alpha blending an image of the child control on top of the bitmap, then rendering the bitmap onscreen.
In Windows 8, the WS_EX_LAYERED window style (which is what Tform's TransparentColor and AlphaBlendValue properties use internally) has finally been implemented for child controls.

Related

How can I get transparent images to appear on TMenu item

I have recently converted from Image Lists to Virtual Image Lists and Image Collection controls. All my images are stored in the TImageCollection as png files with transparency. They render fine on the toolbar tool buttons but these same images are not rendered as transparent images with TMainMenu. Do I need to render all menus using Owner Draw?
Embarcadero only add the TImageCollection and TVirtualImageList components (the old component does not change). Lot of old components do not call the DoDraw method from the TImageList or TVirtualImageList component (almost each use own method for transparency). Even the components calling the DoDraw method from TImageList don't always work correctly (problems with styles).
They also use 'outdated' methods for transparent images (do not use alpha blending almost in all old components).
I make own descending components (transparent image, speed button, toolbar, tree view, tabcontrol), TImageCollection and TVirtualImageList. But not the TMenu component (use only my version of TImageCollection and TVirtualImageList) because TMenu calls the DoDraw method from TImageList/TVirtualImageList for drawing icons.
I think Embarcadero must change drawing pictures in components. They need call DoDraw method from TImageList/TVirtualImageList in all components with pictures.

How does clDefault color work?

I noticed some unusual behaviors using clDefault color.
clDefault = TColor($20000000); //536870912
As an example (http://wiki.freepascal.org/Colors):
Using it for Brush will use the normal background brush of the target
DC (device context).
On a Form's canvas a FillRect will paint a
rectangular area filled with the normal background of a standard
window. This is whatever the widgetset and theme defines. This might
be the color gray or a gradient or a picture.
Using clDefault on the
Canvas of a TListBox will paint with the normal background, which is
normally white on Windows. So in a TListBox clDefault is the same as
clWindow.
Using it as Pen color will use the default line color for
the device context.
Using it as Font color will use the normal text
color of the device context.
Could someone tell me how clDefault works?
I mean, is it interpreted by the OS or by the VCL code and how?
You provide a link to FPC documentation, but then talk about the VCL and tag the question Delphi. I'm going to assume that you are asking about Delphi VCL and just ignore your linked documentation which does not apply.
In the VCL, for pens, fonts, and brushes, the default color is black. That's because $20000000 has 0 for R, G and B channels. The alpha channel is $20, but is ignored, certainly for methods like LineTo, FillRect, etc. This is quite different from the FPC documentation you linked to.
If you use clDefault for the Color of a TListBox, then it will again be black. Again, different from the FPC documentation you linked to.
Certainly the value $20000000 has no special meaning to GDI. For pens, fonts, brushes etc. the value is passed down to GDI which interprets it as black.
If you study the VCL source code you will find a variety of places where clDefault is used. In the main clDefault is used as a sentinel value. The VCL code checks whether or not a specified color property is equal to clDefault, and then takes special action if it is.
So far as I can tell, that's all there is to it. Some parts of the VCL treat clDefault as a sentinel, otherwise it is black.

What does the CapInsets property of a FireMonkey TBitmapLink do for a FireMonkey style?

When creating a custom FireMonkey style, you often run into style objects, such as TButtonStyleObject, that include one or more properties (such as TButtonStyleObject.NormalLink) that are collections of TBitmapLinks. Each individual TBitmapLink defines three properties, CapInsets, Scale, and SourceRect. SourceRect contains the coordinates of a segment of a bitmap that will be used to draw some aspect of the control (see Using TBitmapLinks with the FireMonkey Style Designer for more detail).
My question is, what does CapInsets do?
I think it is something related how to paint a resizable component using a single bitmap. The CapInsets should represent the stretchable portion of the bitmap leaving apart, in example, the borders so they do not get too thin or too large when you resize the component.
Think about a button and a 25x50 px bitmap to be the backround. Think it is a single color rectangle with a little border. What if you resize the button to be 25x500 px? The left and right border will become too large (and no more proportional to the top and bottom border).
I found no documentation except this article in russian (translation to italian is very bad, the english one isn't so clear to me as well), look for the "Background" section http://habrahabr.ru/post/137851/
HTH

form:Transparent, Control on form:non Transparent?

How can change alphablend of a form without affect on control in form?
Delphi XE7
One solution to this problem is to use Multi-Device Application (if using VCL is not possible).
If you need to leave a transparent TForm just changing a property Transparency = True.
If you need to leave a semi-transparent component, all components have the Opacity property that can be assigned a more transparent value between 0 and 1, where 0 is closer to that component.
For example you could put the controls within a TLayout and change the Opacity of it as you see fit, and have no effect on the other components, or vice versa.
Actually the answer to this might be pretty simple...(for windows only)
The JEDI VCL library has a component (TJvTransparentForm) that allows you to take an Alpha blended PNG image (ie the gray background shown in your picture above) and use it to make a form control. The picture is actually stored in a TImage and you would need to place your "Icons" on the image itself. Then just respond to the mouse clicks on the TImage.
You have what your asking for (maybe?).
If you were tricky enough you could probably even track the mouse movement and change the Image to glow the correct "button" that the mouse was over.

How to put a transparent color on a form?

I have a form with an image as the background.
Now I need to put several transparent dark color areas in several areas off the form.
I need not to hide the background. How can I do this?
Standard Delphi control do AFAIK not support that kind of transparency. You therefore have two possiblities:
use third-party components
create your own component (you can derive from an existing one) and override the paint method. In the paint method just draw the correct part of the background image and darken every pixel to get the effect you want.
You can try Delphi 2009/2010 which supports using PNG images. The PNG image format allows for alpha layer transparency, which it sounds it what your looking for. This assumes that your wanting a fixed shape on your form.
EDIT-- For Delphi 2007, you can attempt to use the PNG Components which if I remember correctly do properly handle alpha transparency.
Is the background image and the darker areas the only thing that you want on your form, or do you have other components that should be blended too?
If it's only the background image and the dark areas, I would recommend that you check out Graphics32. It's an image control supporting layers. It should be fairly easy to archive what you want (or what I assume that you want...) from that.

Resources