Accueil > > > PANEL ET CHECKBOX
PANEL ET CHECKBOX
Information sur la source
Description
Suite de composants avec scanline. Un panel, et un checkbox. Checkbox pouvant être transparent, coché ou plein, et en lecture seule. Exemple.
Source
- unit BFCheckBox;
- interface
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, ExtCtrls, ExtDlgs, Spin, FileCtrl, ComCtrls;
- Const
- PixelCountMax=32768; {Nombre maxi de pixels}
- TYPE
- pRGBTripleArray=^TRGBTripleArray; {Nom de pointeur}
- TRGBTripleArray=ARRAY[0..PixelCountMax-1]of TRGBTRIPLE; {sur l'ensemble des pixels}
- type
- TBFCheckBox = class(TGraphicControl)
- private
- { Déclarations privées }
- FBROUGE:Byte;
- FBVERT:Byte;
- FBBLEU:Byte;
- FBChecked:Boolean; //Case a cocher
- FBChPlein:Boolean; //plein ou coché
- FBTransparent:Boolean; //Composant devenant transparent
- FBCaption:string;
- FBReadOnly:Boolean; //Lecture seule
-
- Procedure SETBROUGE(Value:Byte);
- Procedure SETBVERT(Value:Byte);
- Procedure SETBBLEU(Value:Byte);
- Procedure SETBTRANSPARENT(Value:boolean);
- Procedure SETBCHECKED(Value:boolean);
- Procedure SETBCHPLEIN(Value:boolean);
- Procedure SETBCAPTION(Value:string);
- Procedure SETBReadOnly(Value:boolean);
-
- protected
- { Déclarations protégées }
- procedure Paint; override;
- Procedure TransformeCheckBox(Var FBRouge, FBVert, FBBleu:Byte;FBTransparent:Boolean;
- FBChecked:boolean;FBCaption:string);
-
- public
- { Déclarations publiques }
- constructor Create(AOwner:TComponent); override;
- Destructor Destroy;Override;
- Procedure Click;Override;
-
- published
- { Déclarations publiées }
- Property ROUGE:Byte READ FBROUGE WRITE SETBROUGE;
- Property VERT:Byte READ FBVERT WRITE SETBVERT;
- Property BLEU:Byte READ FBBLEU WRITE SETBBLEU;
- Property Transparent:Boolean READ FBTransparent WRITE SETBTRANSPARENT;
- Property Checked:Boolean Read FBChecked Write SETBCHECKED;
- Property CHPlein:Boolean READ FBCHPLEIN Write SETBCHPLEIN;
- Property Caption:string READ FBCAPTION WRITE SETBCAPTION;
- Property ReadOnly:Boolean READ FBReadOnly WRITE SETBReadOnly;
- Property Action;
- Property Anchors;
- Property BidiMode;
- Property Constraints;
- Property Cursor;
- Property DragCursor;
- Property DragKind;
- Property DragMode;
- Property Enabled;
- Property Font;
- Property Height;
- Property Hint;
- Property Left;
- Property Name;
- Property ParentBiDiMode;
- Property ParentFont;
- Property ParentShowHint;
- Property PopupMenu;
- Property ShowHint;
- Property Tag;
- Property Top;
- Property Visible;
- Property Width;
- property OnClick;
- property OnDblClick;
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
-
- end;
-
- procedure Register;
-
- Var
- Image : Timage;
-
- implementation
-
- procedure TBFCheckBox.Paint;
- begin
- inherited Paint;
- with Canvas do
- begin
- TransformeCheckBox(FBrouge,FBvert,FBbleu,FBTransparent,FBChecked,FBCaption);
- Canvas.Draw(0,0,Image.Picture.Graphic);
- Image.Free;
- If FBTransparent= false then
- begin
- Brush.Style:=bsClear; {Spécifie le motif du pinceau}
- Pen.Width:=4; {grosseur du pinceau}
- Pen.Color:=RGB(FBROUGE,FBVERT,FBBLEU); {on récupère la couleur de bordure}
- Rectangle(0,0,Width,Height); {on dessine le rectangle}
- end;
- end;
- end;
-
- Procedure TBFCheckBox.TransformeCheckBox(Var FBRouge, FBVert, FBBleu:Byte;FBTransparent:Boolean;
- FBChecked:boolean;FBCaption:string);
- VAR
- Btmap1 : TBitmap; {bitmaps}
- I,J,w,h:integer;
- Row:pRGBTripleARRAY;
- Dr,Ha,Hc:Integer;
- D2,D4,D8:integer;
- begin
- Image:=TImage.Create(Self); //Création et dimension de l'image
- Hc:=-Font.Height; //Hauteur de fonte
- Height:=Hc+6; //Hauteur du composant calculée
- Ha:=Hc+2;
- D2:=Round(Ha/2); //Pour le dessin de la case cochée
- D4:=Round(Ha/4);
- D8:=Round(Ha/8);
- W:=Width;
- H:=Height;
- Image.Width :=W ;
- Image.Height :=H ;
- Btmap1 := TBitmap.Create;
- TRY
- Btmap1.PixelFormat := pf24bit; //Création du bitmap aux mêmes dimentions que l'image
- Btmap1.Width := W;
- Btmap1.Height:=H;
- for J:=0 to BTMap1.Height-1 do //Avec Scanline
- begin
- Row:=BtMap1.Scanline[j];
- for i:=0 to BTMap1.Width-1 do
- begin
- With Row[i] do
- begin
- RGBTRed:=FBRouge;
- RGBTGreen:=FBVert;
- RGBTBlue:=FBBleu;
- end;
- end;
- end;
- With Image do
- begin
- Picture.Graphic := Btmap1; //Récupération de l'image
- Ha:=H-4;
- Dr:=6+Ha;
- Canvas.Brush.Style:=bsClear;
- Canvas.Draw(0,0,Btmap1);
- Canvas.Font.Size:=Font.Size; {la grosseur de caractère}
- Canvas.Font.Name:=Font.Name; {le nom de la fonte d'écriture}
- Canvas.Font.Color:=Font.Color; {la couleur}
- Transparent:=FBTransparent; {Transparence}
- if FBCaption<>'' then
- Canvas.textOut(Dr,1,FBCaption); {on écrit le texte}
- Canvas.Brush.Style:=bssolid;
- If FBChecked=true then //Case cochée
- Begin
- If FBChPlein=true then //Carré plein
- begin
- Canvas.Brush.color:=ClBlack;
- Canvas.Rectangle(2,2,Ha,Ha);
- end
- else
- begin
- Canvas.Pen.Width:=1; //Case cochée
- Canvas.Brush.color:=ClWhite;
- Canvas.Rectangle(2,2,Ha,Ha);
- Canvas.Brush.color:=ClBlack;
- if Font.size>10 then
- Canvas.Pen.Width:=3;
- Canvas.MoveTo(D4+1,D2+1);
- Canvas.LineTo(d2+1,(7*d8));
- Canvas.LineTo((3*D4),D8);
- end;
- end
- else
- begin //Case non cochée
- Canvas.Pen.Width:=1;
- Canvas.Brush.color:=ClWhite;
- Canvas.Rectangle(2,2,Ha,Ha);
- end;
- END;
- FINALLY
- Btmap1.Free;
- END;
- END;
-
- Procedure TBFCheckBox.SETBROUGE(Value:Byte);
- Begin
- if Value <> FBROUGE then
- begin
- FBROUGE := Value;
- Invalidate;
- end;
- End;
-
- Procedure TBFCheckBox.SETBVERT(Value:Byte);
- Begin
- if Value <> FBVERT then
- begin
- FBVERT := Value;
- Invalidate;
- end;
- End;
-
- Procedure TBFCheckBox.SETBBLEU(Value:Byte);
- Begin
- if Value <> FBBLEU then
- begin
- FBBLEU := Value;
- Invalidate;
- end;
- End;
-
- Procedure TBFCheckBox.SETBTRANSPARENT(Value:Boolean);
- Begin
- if Value <> FBTransparent then
- begin
- FBTransparent := Value;
- Invalidate;
- end;
- End;
-
- Procedure TBFCheckBox.SETBCHECKED(Value:Boolean);
- Begin
- if Value <> FBChecked then
- begin
- FBChecked := Value;
- Invalidate;
- end;
- End;
-
- Procedure TBFCheckBox.SETBCHPLEIN(Value:boolean);
- Begin
- if Value <> FBChPlein then
- begin
- FBChPlein := Value;
- Invalidate;
- end;
- End;
-
- Procedure TBFCheckBox.SETBReadOnly(Value:boolean);
- Begin
- if Value <> FBReadOnly then
- begin
- FBReadOnly := Value;
- Invalidate;
- end;
- end;
-
- Procedure TBFCheckBox.SETBCAPTION(Value:string);
- Begin
- if Value <> FBCaption then
- begin
- FBCaption := Value;
- Invalidate;
- end;
- end;
-
- Procedure TBFCheckBox.Click;
- Begin
- If FBReadOnly=true then
- exit;
- Checked:= Not Checked;
- Invalidate;
- InHerited Click;
- end;
-
- constructor TBFCheckBox.Create(AOwner:TComponent);
- begin
- inherited;
- Width:=97;
- Height:=17;
- FBRouge:=180;
- FBVert:=180;
- FBBleu:=240;
- FBTransparent:=True;
- FBChecked:=False;
- Checked:=False;
- FBChPlein:=False;
- FBReadOnly:=False;
- FBCaption:='';
- end;
-
- Destructor TBFCheckBox.Destroy;
- Begin
- Inherited Destroy;
- end;
-
- procedure Register;
- begin
- RegisterComponents('Exemples', [TBFCheckBox]);
- end;
- end.
unit BFCheckBox;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, ExtDlgs, Spin, FileCtrl, ComCtrls;
Const
PixelCountMax=32768; {Nombre maxi de pixels}
TYPE
pRGBTripleArray=^TRGBTripleArray; {Nom de pointeur}
TRGBTripleArray=ARRAY[0..PixelCountMax-1]of TRGBTRIPLE; {sur l'ensemble des pixels}
type
TBFCheckBox = class(TGraphicControl)
private
{ Déclarations privées }
FBROUGE:Byte;
FBVERT:Byte;
FBBLEU:Byte;
FBChecked:Boolean; //Case a cocher
FBChPlein:Boolean; //plein ou coché
FBTransparent:Boolean; //Composant devenant transparent
FBCaption:string;
FBReadOnly:Boolean; //Lecture seule
Procedure SETBROUGE(Value:Byte);
Procedure SETBVERT(Value:Byte);
Procedure SETBBLEU(Value:Byte);
Procedure SETBTRANSPARENT(Value:boolean);
Procedure SETBCHECKED(Value:boolean);
Procedure SETBCHPLEIN(Value:boolean);
Procedure SETBCAPTION(Value:string);
Procedure SETBReadOnly(Value:boolean);
protected
{ Déclarations protégées }
procedure Paint; override;
Procedure TransformeCheckBox(Var FBRouge, FBVert, FBBleu:Byte;FBTransparent:Boolean;
FBChecked:boolean;FBCaption:string);
public
{ Déclarations publiques }
constructor Create(AOwner:TComponent); override;
Destructor Destroy;Override;
Procedure Click;Override;
published
{ Déclarations publiées }
Property ROUGE:Byte READ FBROUGE WRITE SETBROUGE;
Property VERT:Byte READ FBVERT WRITE SETBVERT;
Property BLEU:Byte READ FBBLEU WRITE SETBBLEU;
Property Transparent:Boolean READ FBTransparent WRITE SETBTRANSPARENT;
Property Checked:Boolean Read FBChecked Write SETBCHECKED;
Property CHPlein:Boolean READ FBCHPLEIN Write SETBCHPLEIN;
Property Caption:string READ FBCAPTION WRITE SETBCAPTION;
Property ReadOnly:Boolean READ FBReadOnly WRITE SETBReadOnly;
Property Action;
Property Anchors;
Property BidiMode;
Property Constraints;
Property Cursor;
Property DragCursor;
Property DragKind;
Property DragMode;
Property Enabled;
Property Font;
Property Height;
Property Hint;
Property Left;
Property Name;
Property ParentBiDiMode;
Property ParentFont;
Property ParentShowHint;
Property PopupMenu;
Property ShowHint;
Property Tag;
Property Top;
Property Visible;
Property Width;
property OnClick;
property OnDblClick;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
end;
procedure Register;
Var
Image : Timage;
implementation
procedure TBFCheckBox.Paint;
begin
inherited Paint;
with Canvas do
begin
TransformeCheckBox(FBrouge,FBvert,FBbleu,FBTransparent,FBChecked,FBCaption);
Canvas.Draw(0,0,Image.Picture.Graphic);
Image.Free;
If FBTransparent= false then
begin
Brush.Style:=bsClear; {Spécifie le motif du pinceau}
Pen.Width:=4; {grosseur du pinceau}
Pen.Color:=RGB(FBROUGE,FBVERT,FBBLEU); {on récupère la couleur de bordure}
Rectangle(0,0,Width,Height); {on dessine le rectangle}
end;
end;
end;
Procedure TBFCheckBox.TransformeCheckBox(Var FBRouge, FBVert, FBBleu:Byte;FBTransparent:Boolean;
FBChecked:boolean;FBCaption:string);
VAR
Btmap1 : TBitmap; {bitmaps}
I,J,w,h:integer;
Row:pRGBTripleARRAY;
Dr,Ha,Hc:Integer;
D2,D4,D8:integer;
begin
Image:=TImage.Create(Self); //Création et dimension de l'image
Hc:=-Font.Height; //Hauteur de fonte
Height:=Hc+6; //Hauteur du composant calculée
Ha:=Hc+2;
D2:=Round(Ha/2); //Pour le dessin de la case cochée
D4:=Round(Ha/4);
D8:=Round(Ha/8);
W:=Width;
H:=Height;
Image.Width :=W ;
Image.Height :=H ;
Btmap1 := TBitmap.Create;
TRY
Btmap1.PixelFormat := pf24bit; //Création du bitmap aux mêmes dimentions que l'image
Btmap1.Width := W;
Btmap1.Height:=H;
for J:=0 to BTMap1.Height-1 do //Avec Scanline
begin
Row:=BtMap1.Scanline[j];
for i:=0 to BTMap1.Width-1 do
begin
With Row[i] do
begin
RGBTRed:=FBRouge;
RGBTGreen:=FBVert;
RGBTBlue:=FBBleu;
end;
end;
end;
With Image do
begin
Picture.Graphic := Btmap1; //Récupération de l'image
Ha:=H-4;
Dr:=6+Ha;
Canvas.Brush.Style:=bsClear;
Canvas.Draw(0,0,Btmap1);
Canvas.Font.Size:=Font.Size; {la grosseur de caractère}
Canvas.Font.Name:=Font.Name; {le nom de la fonte d'écriture}
Canvas.Font.Color:=Font.Color; {la couleur}
Transparent:=FBTransparent; {Transparence}
if FBCaption<>'' then
Canvas.textOut(Dr,1,FBCaption); {on écrit le texte}
Canvas.Brush.Style:=bssolid;
If FBChecked=true then //Case cochée
Begin
If FBChPlein=true then //Carré plein
begin
Canvas.Brush.color:=ClBlack;
Canvas.Rectangle(2,2,Ha,Ha);
end
else
begin
Canvas.Pen.Width:=1; //Case cochée
Canvas.Brush.color:=ClWhite;
Canvas.Rectangle(2,2,Ha,Ha);
Canvas.Brush.color:=ClBlack;
if Font.size>10 then
Canvas.Pen.Width:=3;
Canvas.MoveTo(D4+1,D2+1);
Canvas.LineTo(d2+1,(7*d8));
Canvas.LineTo((3*D4),D8);
end;
end
else
begin //Case non cochée
Canvas.Pen.Width:=1;
Canvas.Brush.color:=ClWhite;
Canvas.Rectangle(2,2,Ha,Ha);
end;
END;
FINALLY
Btmap1.Free;
END;
END;
Procedure TBFCheckBox.SETBROUGE(Value:Byte);
Begin
if Value <> FBROUGE then
begin
FBROUGE := Value;
Invalidate;
end;
End;
Procedure TBFCheckBox.SETBVERT(Value:Byte);
Begin
if Value <> FBVERT then
begin
FBVERT := Value;
Invalidate;
end;
End;
Procedure TBFCheckBox.SETBBLEU(Value:Byte);
Begin
if Value <> FBBLEU then
begin
FBBLEU := Value;
Invalidate;
end;
End;
Procedure TBFCheckBox.SETBTRANSPARENT(Value:Boolean);
Begin
if Value <> FBTransparent then
begin
FBTransparent := Value;
Invalidate;
end;
End;
Procedure TBFCheckBox.SETBCHECKED(Value:Boolean);
Begin
if Value <> FBChecked then
begin
FBChecked := Value;
Invalidate;
end;
End;
Procedure TBFCheckBox.SETBCHPLEIN(Value:boolean);
Begin
if Value <> FBChPlein then
begin
FBChPlein := Value;
Invalidate;
end;
End;
Procedure TBFCheckBox.SETBReadOnly(Value:boolean);
Begin
if Value <> FBReadOnly then
begin
FBReadOnly := Value;
Invalidate;
end;
end;
Procedure TBFCheckBox.SETBCAPTION(Value:string);
Begin
if Value <> FBCaption then
begin
FBCaption := Value;
Invalidate;
end;
end;
Procedure TBFCheckBox.Click;
Begin
If FBReadOnly=true then
exit;
Checked:= Not Checked;
Invalidate;
InHerited Click;
end;
constructor TBFCheckBox.Create(AOwner:TComponent);
begin
inherited;
Width:=97;
Height:=17;
FBRouge:=180;
FBVert:=180;
FBBleu:=240;
FBTransparent:=True;
FBChecked:=False;
Checked:=False;
FBChPlein:=False;
FBReadOnly:=False;
FBCaption:='';
end;
Destructor TBFCheckBox.Destroy;
Begin
Inherited Destroy;
end;
procedure Register;
begin
RegisterComponents('Exemples', [TBFCheckBox]);
end;
end.
Conclusion
Le Panel est joint. Si vous apportez des modifs, je suis preneur.
Sources du même auteur
Sources de la même categorie
Commentaires et avis
Discussions en rapport avec ce code source dans le forum
Forme en i pour eviter de nombreuses lignes [ par Valentin_Loupe ]
Bonjour, je suis débutant en delphi et je voudrais savoir comment je peux faire pour par exemple changer la couleur de 15 panels avec 15 checkbox
composant panel [ par saravana ]
bjr a tous je veux commencer a creer des composants et j'ai besoin de votre aide,est ce que quelqun peut me donner le source d'un composant panel avec
Drag and Drop [ par Rush_Beck ]
Bonjour,J'utilise le drag and drop pour faire glisser un Panel au dessus d'une grille, J'ai positioné Panel1.Dragkind := dkDock sans quoi le glisser d
PB pour dessiner sur un Canvas je séche... [ par ffert ]
Bonjour Voilà un des Bug les plus incompréhensible que j'ai rencontré.... : J'ai un Panel contenant un TImage. Le Panel est en "Visible := False" à l'
Probleme de Parent [ par anisb ]
Bonjour à tous,Je vais essayer d'être clair... 1) Mon projet contient une Form: dans le formCreate, j'instancie un certain nombre de Panel dont le Own
Aligner des éléments avec les Anchors [ par DragonicFlash ]
Bonjour à tous, J'utilise actuellement BDS 2006 pour faire une application .Net. L'application est terminée, et je suis en train de "l'habiller". <i
Programme autonome [ par Valentin_Loupe ]
Bonjour, Je suis débutant en delphi et je voudrais savoir comment je peux, le plus simplement possible, faire afficher un même panel en différentes co
DLL utilisant des fiches VCL dans un Panel [ par Swiathowski ]
Bonjour,j'ai une DLL contenant des fiches VCL. Si j'appele une fiche avec un showmodal, cela fonctionne très bien, par contre si je veux afficher cett
Impossible de focaliser une fenêtre désactivée ou invisible [ par Guillemouze ]
bien le bonjour, me revoila pour une question un peu bete mais je ne trouve pas de solution.j'ai une form qui contient plusieurs panels, qu'on peut as
|
Derniers Blogs
ETENDRE LE TEAM WEB ACCESS DE TFS 2012 - STEP 0ETENDRE LE TEAM WEB ACCESS DE TFS 2012 - STEP 0 par Philess
L'extensibilité du Team Web Access
Le Web Access (site d'équipe) de Team Foundation Server a été complètement réécrit dans la version 2012 avec pas moins de 400.000 lignes de JavaScript. Ce nouveau modèle a été pensé pour offrir de grandes...
Cliquez pour lire la suite de l'article par Philess SIMULER FACILEMENT L'ENVOI DE MAILSIMULER FACILEMENT L'ENVOI DE MAIL par JeremyJeanson
il m'a été demandé, à plusieurs reprises, comment je faisais pour simuler l'envoi de mail lors de mes démos de Workflow Foundation. Ma solution est plutôt simple : j'utilise la configuration par défaut du SmtpClient et j'oriente les mails vers un dossier ...
Cliquez pour lire la suite de l'article par JeremyJeanson VOTEZ POUR LE TOP 10 DES INFLUENCEURS SHAREPOINT FRANCOPHONES !VOTEZ POUR LE TOP 10 DES INFLUENCEURS SHAREPOINT FRANCOPHONES ! par Patrick Guimonet
Si ce n'est déjà fait (comme plus de 600 personnes déjà), il est encore temps de voter pour le concours TOP 10 des influenceurs SharePoint francophones ! Il est organisé par harmon.ie et accessible ici : http://harmon.ie/top-...
Cliquez pour lire la suite de l'article par Patrick Guimonet [CONF'SHAREPOINT] DERNIER RAPPEL ! :-)[CONF'SHAREPOINT] DERNIER RAPPEL ! :-) par Patrick Guimonet
La Conf'SharePoint en chiffres c'est : 3 jours de SharePoint ! 4 parcours et 60 sessions 17 partenaires représentant toutes les fac...
Cliquez pour lire la suite de l'article par Patrick Guimonet
Logiciels
Easy-Planning (4.5.0.11)EASY-PLANNING (4.5.0.11)Easy-Planning permet de créer des plannings sous la représentation de diagrammes et est adapté a... Cliquez pour télécharger Easy-Planning CVEasy (3.1.0.51)CVEASY (3.1.0.51)PHMSD-CVEasy est un logiciel d'aide à la rédaction de CV d'une simplicité déconcertante.
PHMSD-C... Cliquez pour télécharger CVEasy LettresFaciles 2011 (8.6.0.31)LETTRESFACILES 2011 (8.6.0.31)LettresFaciles est un logiciel facilitant la création et la rédaction de lettres types.
Son inte... Cliquez pour télécharger LettresFaciles 2011 sDEVIS-FACTURES vlPRO (8.4.2.62)SDEVIS-FACTURES VLPRO (8.4.2.62)sDEVIS-FACTURES vlPRO a été mis au point pour les particuliers, créateurs, entrepreneurs, artisa... Cliquez pour télécharger sDEVIS-FACTURES vlPRO Devis-Factures PHMSD (2.1.0.11)DEVIS-FACTURES PHMSD (2.1.0.11)Configuration minimale
Nécessite Windows™ 2000, XP, Windows 7, 8, Vista (Service Pack à... Cliquez pour télécharger Devis-Factures PHMSD
|