Watch, Follow, &
Connect with Us

For forums, blogs and more please visit our
Developer Tools Community.


Welcome, Guest
Guest Settings
Help

Thread: TLabel Transparency


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 0
Mario Sassone

Posts: 12
Registered: 10/28/06
TLabel Transparency  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Sep 14, 2015 4:48 AM
Hi all,
first time on this forum, so please forgive me if I dont know yet how to use it.

My question is:

When I put a TLabel onto a TImage (showing a background bitmap picture) the TLabel background can be set transparent with MyLabel->Transparent = true;
When the background bitmap picture is shown through the parent form canvas (addressed as a TControlCanvas) the TLabel transparency does not work.
Here the code in the two versions:

void __fastcall TMyForm::FormActivate(TObject *Sender)
 
	Image1->Top    = 150;
	Image1->Left   = 400;
	Image1->Width  = 200;
	Image1->Heigth = 200;
 
	Label1->Top  = 232;
	Label1->Left = 464;
 
	// ---- Loading the background bitmap ----
        Graphics::TBitmap *bkgBitmap = new Graphics::TBitmap;
	bkgBitmap->LoadFromFile(GetCurrentDir() + "\\Sfondo800x500.bmp");
 
	// ---- Copying a 200x200 portion of background on 'Image1' ----
	BLENDFUNCTION bf;
	bf.BlendOp             = AC_SRC_OVER;
	bf.BlendFlags          = false;
        bf.SourceConstantAlpha = 255;
	bf.AlphaFormat         = false;
        Update();
	::AlphaBlend(Image1->Canvas->Handle,     0,   0, 200, 200,
	             bkgBitmap->Canvas->Handle,  0,   0, 200, 200, bf);
 
	Label1->Transparent = true;
	Label1->Repaint();
 
	// ---- The TLabel is rendered with a transparent background ----
	delete bkgBitmap;
}
 
void __fastcall TMyForm::FormActivate(TObject *Sender)
{
	Label1->Top  = 232;
	Label1->Left = 464;
 
	// ---- Loading the background bitmap ----
	Graphics::TBitmap *bkgBitmap = new Graphics::TBitmap;
	bkgBitmap->LoadFromFile(GetCurrentDir() + "\\Sfondo800x500.bmp");
 
	// ---- Addressing the form canvas ----
	formCanvas = new TControlCanvas();
	formCanvas->Control = this;
 
	// ---- Copying a 200x200 portion of background on the form canvas ----
	BLENDFUNCTION bf;
	bf.BlendOp             = AC_SRC_OVER;
	bf.BlendFlags          = false;
	bf.SourceConstantAlpha = 255;
	bf.AlphaFormat 	       = false;
 
	Update();
	::AlphaBlend(formCanvas->Handle,       400, 150, 200, 200,
	             bkgBitmap->Canvas->Handle,  0,   0, 200, 200, bf);
 
	Label1->Transparent = true;
	Label1->Repaint();
 
	// ---- The TLabel is rendered in a uniformly colored rectangle
 
	delete bkgBitmap;
	delete formCanvas;
}


Many thanks for your help,

Mario
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02