使用Borland C++ Builder 2009
我从一个W7窗口对话框中捕捉到三个按钮,并将它们放在TImageList中。在适当情况下,我会在TImage中加载这3种变体。
Image->Picture->Bitmap = NULL ; // Clear previous state
ImageList->GetBitmap(2, Image->Picture->Bitmap) ;
PS:Image->Transparent = True
在Windows 7和Windows 10上,这似乎是正常工作的。但我刚刚意识到,仅仅是因为TImage放在的TImage具有完全相同的背景color
。(在我将背景改为石灰后,已确认不工作)
在Windows上,按钮看起来不太好。因为XP的背景颜色似乎略有不同。请注意,它也是clBtnFace
XP:
。。。Windows 7:
我还试验了设置BlendColor
和DrawingStyle
的TImageList控件,结合Image->Transparent = true
或false
。
但我不能让它起作用。
我在W7上捕获了W7值,并将其放入ImageList->BlendColor
(ImageList->DrawingStyle = dsFocus
或dsSelected
)等等,但没有成功。
我还试验了在Image->Transparent = True
之后再次显式设置ImageList->GetBitmap(2, Image->Picture->Bitmap)
,甚至尝试过
Image->Picture->Bitmap->TransparentColor =
Image->Picture->Bitmap->Canvas->Pixels[0][0]
没有明显的效果。
你的想法?
发布于 2015-12-11 16:45:37
我在评论中说的是什么,而不是从屏幕上捕获图像,您可以尝试使用传递DrawThemeBackground
部件和有效状态之一的TDLG_EXPANDOBUTTON
方法来绘制展开按钮(TDLGEBS_NORMAL
、TDLGEBS_HOVER
、TDLGEBS_PRESSED
等)。对于Windows,您可以使用EBP_NORMALGROUPEXPAND
部件和其中一种状态(EBHC_NORMAL
、EBHC_HOT
、EBHC_PRESSED
)
检查此示例,其中绘制了TImage中的扩张性按钮。
#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);
}
}
}
}
}
https://stackoverflow.com/questions/34194298
复制相似问题