[英]VCL TImage + TImageList, transparent feature doesn't work or what am I doing wrong?
Using Borland C++ Builder 2009 使用Borland C ++ Builder 2009
I screen-captured three buttons from a W7 Windows dialog and put them in a TImageList. 我从W7 Windows对话框中捕获了三个按钮,并将它们放在TImageList中。 I load the 3 variants in a TImage, when appropriate.
适当时,我将3个变体加载到TImage中。
Image->Picture->Bitmap = NULL ; // Clear previous state
ImageList->GetBitmap(2, Image->Picture->Bitmap) ;
PS: Image->Transparent = True
PS:图像-
Image->Transparent = True
On Windows 7 and Windows 10 this seems to work properly. 在Windows 7和Windows 10上,这似乎可以正常工作。 BUT I just realized, only because the TForm the TImage is placed on has the exact same background
color
. 但是我只是意识到,只是因为放置了TImage的TForm具有完全相同的背景
color
。 (confirmed not to work after I changed the background to lime) (确认将背景更改为石灰后不起作用)
On Windows XP the button doesn't look so great. 在Windows XP上,该按钮看起来不太好。 Since XP seems to have slightly different background color.
由于XP似乎具有略有不同的背景色。 Mind you, it's also
clBtnFace
提醒您,它也是
clBtnFace
XP: XP:
.
。 .
。 .
。 Windows 7:
Windows 7的:
I have also experimented with setting BlendColor
and DrawingStyle
of the TImageList control, combined with Image->Transparent = true
or false
. 我还尝试过设置
BlendColor
和DrawingStyle
,并结合Image->Transparent = true
或false
。
But I can't get it to work. 但是我无法正常工作。
I captured the Image->Picture->Bitmap->Canvas->Pixels[0][0]
value on W7 and put it in ImageList->BlendColor
( ImageList->DrawingStyle = dsFocus
or dsSelected
) and so forth, without success. 我在W7上捕获了
Image->Picture->Bitmap->Canvas->Pixels[0][0]
值,并将其放入ImageList->BlendColor
( ImageList->DrawingStyle = dsFocus
或dsSelected
),依此类推,但没有成功。
I also have experimented with explicitly setting Image->Transparent = True
again after a ImageList->GetBitmap(2, Image->Picture->Bitmap)
and even tried 我还尝试过在
ImageList->GetBitmap(2, Image->Picture->Bitmap)
之后再次显式设置Image->Transparent = True
,甚至尝试过
Image->Picture->Bitmap->TransparentColor =
Image->Picture->Bitmap->Canvas->Pixels[0][0]
without a noticeable effect. 没有明显的效果。
Your thoughts ? 你的意见 ?
How I said on my comment instead of capture the image from the screen you can try drawing the expand button using the DrawThemeBackground
method passing the TDLG_EXPANDOBUTTON
part and one of the valid states ( TDLGEBS_NORMAL
, TDLGEBS_HOVER
, TDLGEBS_PRESSED
, etc) . 我在评论中怎么说,而不是从屏幕上捕获图像,您可以尝试使用
DrawThemeBackground
方法绘制扩展按钮,该方法传递TDLG_EXPANDOBUTTON
部分和有效状态之一( TDLGEBS_NORMAL
, TDLGEBS_HOVER
, TDLGEBS_PRESSED
等)。 And for Windows XP you can use EBP_NORMALGROUPEXPAND
part and one of these states ( EBHC_NORMAL
, EBHC_HOT
, EBHC_PRESSED
) 对于Windows XP,您可以使用
EBP_NORMALGROUPEXPAND
部分和以下状态之一( EBHC_NORMAL
, EBHC_HOT
, EBHC_PRESSED
)
Check this sample which drawn the expando button in a TImage. 检查此示例,该示例在TImage中绘制了expando按钮 。
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#include "Vsstyle.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
Image1->Canvas->Brush->Color = clBtnFace;
Image1->Canvas->FillRect(Image1->ClientRect);
OSVERSIONINFO verwin;
verwin.dwOSVersionInfoSize=sizeof(verwin);
if (GetVersionEx(&verwin))
{
//Check the Windows version
if (verwin.dwMajorVersion >= 6) // is Vista at least?
{
HTHEME hTheme = OpenThemeData(Handle, VSCLASS_TASKDIALOG);
if (hTheme)
{
SIZE s;
//get the size of the TDLG_EXPANDOBUTTON
if (GetThemePartSize(hTheme, Image1->Canvas->Handle, TDLG_EXPANDOBUTTON, TDLGEBS_NORMAL, NULL, TS_TRUE, &s) == S_OK)
{
TRect pRect = Rect(0, 0, s.cx, s.cy);
DrawThemeBackground(hTheme, Image1->Canvas->Handle, TDLG_EXPANDOBUTTON, TDLGEBS_NORMAL, &pRect, NULL);
}
}
}
else
{
HTHEME hTheme = OpenThemeData(Handle, VSCLASS_EXPLORERBAR);
if (hTheme)
{
SIZE s;
//get the size of the EBP_NORMALGROUPEXPAND
if (GetThemePartSize(hTheme, Image1->Canvas->Handle, EBP_NORMALGROUPEXPAND, EBHC_NORMAL, NULL, TS_TRUE, &s) == S_OK)
{
TRect pRect = Rect(0, 0, s.cx, s.cy);
DrawThemeBackground(hTheme, Image1->Canvas->Handle, EBP_NORMALGROUPEXPAND, EBHC_NORMAL, &pRect, NULL);
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.