Un bout de code qui rend une Form transparante du centre vers les bords a partir d'un cercle qui grandit
le .cpp
le .h
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50 //--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" #include <math.hpp> //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { // on retire les bordures Form1->BorderStyle = bsNone; // on parametre la Form pour le mode transparent Form1->TransparentColor = true; Form1->TransparentColorValue = clWhite; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { int cmpt = 0; int a; int b; // on dimensionne la Form en plein ecran Form1->Top = 0; Form1->Left = 0; Form1->Width = Screen->Width; Form1->Height = Screen->Height; // on calcule la diagonale ecran qui part du centre vers un coin ecran a = Form1->Height; b = Form1->Width; cmpt = (Hypot(a, b) + 1) / 2; // on trace un cercle avec la couleur transparente (blanc) for(int i =0; i <= cmpt; i++) { Sleep(20); // temporisation Form1->Canvas->Pen->Color = clBtnFace; // pas de trait sur la circonferance Form1->Canvas->Brush->Color = clWhite; // couleur du fond Form1->Canvas->Ellipse((Form1->Width / 2) - i, (Form1->Height / 2) + i, (Form1->Width / 2) + i, (Form1->Height / 2) - i); } } //--------------------------------------------------------------------------- void __fastcall TForm1::Button2Click(TObject *Sender) { Form1->Close(); } //---------------------------------------------------------------------------
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25 //--------------------------------------------------------------------------- #ifndef Unit1H #define Unit1H //--------------------------------------------------------------------------- #include <Classes.hpp> #include <Controls.hpp> #include <StdCtrls.hpp> #include <Forms.hpp> //--------------------------------------------------------------------------- class TForm1 : public TForm { __published: // IDE-managed Components TButton *Button1; TButton *Button2; void __fastcall Button1Click(TObject *Sender); void __fastcall Button2Click(TObject *Sender); private: // User declarations public: // User declarations __fastcall TForm1(TComponent* Owner); }; //--------------------------------------------------------------------------- extern PACKAGE TForm1 *Form1; //--------------------------------------------------------------------------- #endif
Partager