Ver Mensaje Individual
  #14  
Antiguo 07-12-2017
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola.

Con el TLabel no tendrías problemas ya que posee la propiedad Transparent.

Y ya que estamos, código para el CheckBox,

CheckBoxClear.h:
Código PHP:
#ifndef CheckBoxClearH
#define CheckBoxClearH

#include <Classes.hpp>
#include <Controls.hpp>
#include <StdCtrls.hpp>

class TCheckBoxClear : public TCheckBox {
private:
  
TCanvas *FCanvas;
  
TRect FCaptionR;
  
TRect FGlyphR;
protected:
  
void __fastcall CreateParams( TCreateParams &Params );
  
void __fastcall CreateWnd( void );
  
void __fastcall SetButtonStyle( void );
  
void __fastcall CNDrawItem( TWMDrawItem &msg );
  
BEGIN_MESSAGE_MAP
    VCL_MESSAGE_HANDLER
( CN_DRAWITEM, TWMDrawItem, CNDrawItem )
  
END_MESSAGE_MAP( TCheckBox )
public:
  
__fastcall TCheckBoxClear( TComponent *Owner ) : TCheckBox( Owner ) {};
  
//...
};

#endif 
CheckBoxClear.cpp:
Código PHP:
#define OEMRESOURCE

#pragma hdrstop

#include "CheckBoxClear.h"

#pragma package(smart_init)

void __fastcall TCheckBoxClear::CreateParams( TCreateParams &Params )
{
  
TCustomCheckBox::CreateParams( Params );
  
Params.ExStyle |= WS_EX_TRANSPARENT;
}

void __fastcall TCheckBoxClear::CreateWnd( void )
{
  
TCheckBox::CreateWnd();
  
SetButtonStyle();
}

void __fastcall TCheckBoxClear::SetButtonStyle()
{
  const 
BS_MASK = 0x000F;
  
unsigned int Style;

  if ( 
HandleAllocated() ) {
    
Style = BS_CHECKBOX | BS_OWNERDRAW;
    if ( 
GetWindowLong( Handle, GWL_STYLE) & BS_MASK != Style )
      
SendMessage( Handle, BM_SETSTYLE, Style, 1 );
  }
}

void __fastcall TCheckBoxClear::CNDrawItem( TWMDrawItem &msg )
{
  const 
int H = 0xD;
  const 
int W = 0xD;
  
FGlyphR        = msg.DrawItemStruct->rcItem;
  
FGlyphR.Right  = 20;
  
FCaptionR      = msg.DrawItemStruct->rcItem;
  
FCaptionR.Left = FGlyphR.Right;

  
FCanvas = new TCanvas;
  
__try {
    
FCanvas->Handle       = msg.DrawItemStruct->hDC;
    
FCanvas->Brush->Style = bsClear;

    
// Draw TBitmap
    
int x, y, sx=0, sy=0;
    
Graphics::TBitmap *Glyph = new Graphics::TBitmap;
    try {
      
Glyph->Handle = ::LoadBitmap( NULL, MAKEINTRESOURCE( OBM_CHECKBOXES ) );
      
y = FGlyphR.Top + (FGlyphR.Bottom - FGlyphR.Top - H) / 2;
      
x = 2;
      if( 
State == cbChecked ) sx += H;
      if( 
State == cbGrayed )  sx *= W;
      
FCanvas->CopyRect(Rect(x, y, x+W, x+H) ,Glyph->Canvas,
        
Rect(sx, sy, sx+W, sy+H));
    }
    
__finally {
      
delete Glyph;
    }

    
// Draw Caption
    
long fmt = DT_VCENTER |  DT_SINGLELINE | DT_LEFT;
    
fmt = DrawTextBiDiModeFlags( fmt );
    
DrawText(msg.DrawItemStruct->hDC, Caption.c_str(),
      
Caption.Length(), &FCaptionR, fmt);
  }
  
__finally {
    
delete FCanvas;
  }
} 
Prueba:
Código PHP:
...
#include "CheckBoxClear.h"

void __fastcall TForm1::Button1Click(TObject *Sender)
{
  
// Label transparente
  
Label1->Transparent = true;

 
// CheckBox transparente
  
TCheckBoxClear *cbc = new TCheckBoxClear( this );
  
cbc->Left    = 200;
  
cbc->Top     = 110;
  
cbc->Name    = "CheckBoxClear1";
  
cbc->Caption = cbc->Name;
  
cbc->Parent  = this;
  ... 
Muestra:


Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita