He estado probando tu codigo y me encuentro con una serie de problemas a extrapolarlo a otros componentes que necesito tambien hacerlos transparentes y que irán dentro de dicho TPanelClear. Son TGroupBox, TRadioGroup, y TCheckBox. Ademas de que no consigo hacer a ninguno de ellos transparentes con tu codigo, el TCheckBox no me deja ni compilar porque dice que Canvas no se reconoce. Te pego el codigo:
Código PHP:
//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
class TPanelClear : public TPanel {
protected:
void __fastcall CreateParams( TCreateParams &Params ) {
TPanel::CreateParams( Params );
Params.ExStyle |= WS_EX_TRANSPARENT;
}
void __fastcall Paint() {
HDC DC = Canvas->Handle;
TRect R = ClientRect;
Graphics::TBitmap *BM = new Graphics::TBitmap;
try {
BM->Height = Height;
BM->Width = Width;
Canvas->Handle = BM->Canvas->Handle;
TPanel::Paint();
Canvas->Handle = DC;
Canvas->Brush->Style = bsClear;
Canvas->BrushCopy(R, BM, R, Color);
}
__finally {
delete BM;
}
}
public:
__fastcall TPanelClear( TComponent *Owner ) : TPanel( Owner ) {
TPanel::TPanel( Owner );
}
};
//---------------------------------------------------------------------------
void __fastcall TForm1::btShowPanelClearClick(TObject *Sender)
{
TPanelClear *pc = new TPanelClear(this);
pc->Left = 5;
pc->Top = 5;
pc->Height = 50;
pc->Width = 200;
pc->Name = "PanelClear1";
pc->Caption = pc->Name;
pc->Parent = this;
}
//---------------------------------------------------------------------------
class TGroupBoxClear : public TGroupBox {
protected:
void __fastcall CreateParams( TCreateParams &Params ) {
TGroupBox::CreateParams( Params );
Params.ExStyle |= WS_EX_TRANSPARENT;
}
void __fastcall Paint() {
HDC DC = Canvas->Handle;
TRect R = ClientRect;
Graphics::TBitmap *BM = new Graphics::TBitmap;
try {
BM->Height = Height;
BM->Width = Width;
Canvas->Handle = BM->Canvas->Handle;
TGroupBox::Paint();
Canvas->Handle = DC;
Canvas->Brush->Style = bsClear;
Canvas->BrushCopy(R, BM, R, Color);
}
__finally {
delete BM;
}
}
public:
__fastcall TGroupBoxClear( TComponent *Owner ) : TGroupBox( Owner ) {
TGroupBox::TGroupBox( Owner );
}
};
//---------------------------------------------------------------------------
class TCheckBoxClear : public TCheckBox {
protected:
void __fastcall CreateParams( TCreateParams &Params ) {
TCheckBox::CreateParams( Params );
Params.ExStyle |= WS_EX_TRANSPARENT;
}
void __fastcall Paint() {
HDC DC = Canvas->Handle; //Undefined symbol 'Canvas'
TRect R = ClientRect;
Graphics::TBitmap *BM = new Graphics::TBitmap;
try {
BM->Height = Height;
BM->Width = Width;
Canvas->Handle = BM->Canvas->Handle;
TCheckBox::Paint();
Canvas->Handle = DC;
Canvas->Brush->Style = bsClear;
Canvas->BrushCopy(R, BM, R, Color);
}
__finally {
delete BM;
}
}
public:
__fastcall TCheckBoxClear( TComponent *Owner ) : TCheckBox( Owner ) {
TCheckBox::TCheckBox( Owner );
}
};
//---------------------------------------------------------------------------
void __fastcall TForm1::btShowGroupBoxClearClick(TObject *Sender)
{
TGroupBoxClear *gbc = new TGroupBoxClear(this);
gbc->Left = 5;
gbc->Top = 5;
gbc->Height = 60;
gbc->Width = 200;
gbc->Name = "GroupBoxClear1";
gbc->Caption = gbc->Name;
gbc->Parent = this;
//No se crea dentro del GroupBoxClear
TCheckBoxClear *cbc1 = new TCheckBoxClear(this);
cbc1->Left = 10;
cbc1->Top = 10;
cbc1->Name = "CheckBox1";
cbc1->Caption = cbc1->Name;
cbc1->Parent = gbc;
}
//---------------------------------------------------------------------------
class TRadioGroupClear : public TRadioGroup {
protected:
void __fastcall CreateParams( TCreateParams &Params ) {
TRadioGroup::CreateParams( Params );
Params.ExStyle |= WS_EX_TRANSPARENT;
}
void __fastcall Paint() {
HDC DC = Canvas->Handle; //Undefined symbol 'Canvas'
TRect R = ClientRect;
Graphics::TBitmap *BM = new Graphics::TBitmap;
try {
BM->Height = Height;
BM->Width = Width;
Canvas->Handle = BM->Canvas->Handle;
TRadioGroup::Paint();
Canvas->Handle = DC;
Canvas->Brush->Style = bsClear;
Canvas->BrushCopy(R, BM, R, Color);
}
__finally {
delete BM;
}
}
public:
__fastcall TRadioGroupClear( TComponent *Owner ) : TRadioGroup( Owner ) {
TRadioGroup::TRadioGroup( Owner );
}
};
//---------------------------------------------------------------------------
void __fastcall TForm1::btShowRadioGroupClick(TObject *Sender)
{
TRadioGroupClear *rgc = new TRadioGroupClear(this);
rgc->Left = 5;
rgc->Top = 5;
rgc->Height = 100;
rgc->Width = 200;
rgc->Name = "GroupBoxClear1";
rgc->Caption = rgc->Name;
rgc->Parent = this;
rgc->Items->Add("opcion1");
rgc->Items->Add("opcion2");
}
//---------------------------------------------------------------------------
PD: Tu proyecto no me compilaba porque me decia que habia un error de linkado porque faltaba el nombre: "[Linker Fatal Error] Fatal: Expected a file name:"
Una vez consiguiese hacer que todo funcione correctamente la idea ya seria crear componentes con dichos codigos a ver si soy capaz