Form Transparente


O exemplo a seguir cria um form transparente, com apenas uma linha de código:


//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"     
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::FormCreate(TObject *Sender)
{
Brush->Style=bsClear;

//BorderIcons = BorderIcons - (TBorderIcons()<< biMaximize);
//BorderIcons = BorderIcons - (TBorderIcons()<< biMinimize);
//BoderStyle = bsNone;

}
//---------------------------------------------------------------------------



Nota: Normalmente esses códigos para deixar o formulário transparente apresentam um problema de repintura quando o mesmo é arrastado, redimensionado ou quando uma janela é arrastada sobre o mesmo. Podemos alterar, melhorando bastante o código acima:



//---------------------------------------------------------------------------
#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
        : TForm(Owner)
{
BorderStyle = bsNone;
SetWindowLong(Form1->Handle, GWL_EXSTYLE,
GetWindowLong(Form1->Handle, GWL_EXSTYLE) | WS_EX_TRANSPARENT);
Form1->Brush->Style = bsClear;

}
//---------------------------------------------------------------------------

Nota: para encerrar o aplicativo acima, tecle Alt + F4





HOME || MAPA DO SITE || CURSOS || TUTORIAIS || LINKS || FORUM || CONTATO