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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317
| unit MyPanel94;
interface
uses
SysUtils, Classes,Windows, Controls, Graphics,Messages,
ExtCtrls,StdCtrls,QGraphics,JvComponent, JvTransLED,ImgList,Dialogs,JvEdit;
type
TMonPanel94 = class(TCustomPanel)
private
{Déclarations privées}
//mon edit
Label1: Tlabel;
//titre
LabelTitre: string;
//EditTextLargeur:boolean;
LabelCouleur:Tcolor;
//ma combobox
ComboBox1: TComboBox;
// ComboBoxItem : Tstrings;
ComboBoxItem : Tstrings;
//fond gris
Shape1: TShape;
//ma led
LED1: TJvTransLED;
//led visible ou non
LEDBoolVisible:boolean;
//indice pour changer la couleur de la led
LedCoul: integer;
//Ma liste d'image
ImgList: TImageList;
//Mon emplacement d'image
Img: TImage;
ImgDessin:integer;///test
ImgNb : integer;
ImgExist : boolean;
ImgListNom : string;
protected
{ Déclarations protégées }
procedure RedimLabel();
public
{ Déclarations publiques }
//On construit le composant
constructor Create(AOwner: TComponent); override;
//on détruit le composant
Destructor Destroy; override;
//défini la couleur de la led
//changement d'indice pour l'image
procedure ImgOnChange(valIndex:integer);
//permet de récupérer une liste d'image
procedure ImgSetList(ImgNewList: TImageList);
//On met le titre de notre composant en changeant le caption du label
procedure LabelSetTitre(value : string);
//On défini si la led doit être visible ou non
procedure LedSetVisible (LEDvisu : Boolean);
//défini la couleur de la led
procedure LedSetCouleur (Coul : integer);
procedure LabelSetCouleur (TitreCouleur :Tcolor);
procedure ComboBoxAddItem (item : Tstrings);
published
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
property Align ; //
property Alignment ; //
property Anchors ; //
property Autosize ; //
property BevelWidth ; //
property BiDiMode ; //
property BorderStyle ; //
property BorderWidth ; //
property Caption ; //
property Color ; //
property Constraints ; //
property Ctl3D ; //
property Cursor ; //
property DockSite ; //
property DragCursor ; //
property DragKind ; //
property DragMode ; // Propriétés d'un panel classique
property Enabled ; //
property Font ; //
property FullRepaint ; //
property Height ; //
property HelpContext ; //
property HelpType ; //
property Left ; //
property Locked ; //
property Name ; //
property ParentBackground; //
property ParentColor ; //
property ParentCtl3D ; //
property ParentFont ; //
property ParentShowHint ; //
property Showhint ; //
property TabOrder ; //
property Visible ; //
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
//change l'édit
property Titre : string read LabelTitre write LabelSetTitre;
//change la couleur de la led (-1 gris, 0rouge et 1bleu)
property LedCouLeur : integer read LedCoul write LedSetCouleur;
//led visible ou non
property LedVisible : boolean read LEDBoolVisible write LedSetVisible;
//crée la liste d'images
property Images: TImageList read ImgList write ImgSetList;
//on dessine
property ImgIndex : integer read ImgDessin write ImgOnChange;
//couleur sharp
property TitreFondCouleur : Tcolor read LabelCouleur write LabelSetCouleur;
//combobox
property ComboBItem : Tstrings read ComboBoxItem write ComboBoxAddItem;
end;
procedure Register;
implementation
procedure TMonPanel94.ComboBoxAddItem (item : Tstrings);
begin
if ComboBoxItem<>item then
begin
ComboBoxItem:=item;
ComboBox1.Items:=ComboBoxItem;
end;
end;
procedure TMonPanel94.LabelSetCouleur(TitreCouleur : Tcolor);
begin
if LabelCouleur<>TitreCouleur then
begin
LabelCouleur:=TitreCouleur;
// Label1.Color:=TitreCouleur; /////ca marche pas
shape1.Brush.Color:=LabelCouleur;
Shape1.Pen.Color:=ClBtnFace;
end;
end;
//On prend en compte la nouvelle liste d'images
procedure TMonPanel94.ImgSetList(ImgNewList: TImageList);
begin
if ImgList <> ImgNewList then
begin
ImgList:=ImgNewList;
ImgListNom := ImgNewList.Name;
ImgList.name:=ImgListNom;
end;
end;
//On dessine l'image comprise dans la l'image liste, à l'intérieur du cadre délimité par l'image
procedure TMonPanel94.ImgOnChange (ValIndex:integer);
begin
if ValIndex<>ImgDessin then
begin
ImgExist:=false;
ImgDessin:=ValIndex;
ImgNb:=ImgList.count;
Img.Picture.Bitmap := nil;
if ImgNB>=ImgDessin then
begin
if ValIndex>-1 then
begin
ImgList.GetBitmap(valIndex, Img.Picture.Bitmap);
ImgExist:=true;
end;
end;
end;
RedimLabel;
end;
//On prend en compte un changement visible ou non
procedure TMonPanel94.LedSetVisible (LEDvisu : boolean);
begin
if (LEDvisu<>LEDBoolVisible) then
begin
LEDBoolVisible:=LEDvisu;
LED1.Visible:=LEDBoolVisible;
end;
RedimLabel();
end;
procedure TMonPanel94.RedimLabel();
begin
label1.Width:=80;
Label1.Left:=22;
if ImgExist=true then
begin
label1.Left:=Label1.left+24;
Label1.Width:=Label1.width-24 ;
end;
if LED1.Visible=true then
begin
Label1.Width:=label1.width-25;
end;
end;
//On défini la couleur de la diode
procedure TMonPanel94.LedSetCouleur (Coul : integer);
begin
LedCoul := coul;
if Ledcoul<2 then
begin
if ledcoul>-2 then
begin
case coul of
-1 : LED1.color:= clSilver;
0 : LED1.color:= clRed;
1 : LED1.color := clLime;
end;
end;
end;
end;
procedure Register;
begin
RegisterComponents('Standard', [TMonPanel94]);
end;
//on défini le teste du edit et donc le titre de notre composant
procedure TMonPanel94.LabelSetTitre(value : string);
begin
if (LabelTitre <> value) then
begin
LabelTitre:=value;
Label1.Caption:=LabelTitre;
Label1.Alignment:=taCenter;
end;
end;
constructor TMonPanel94.Create(Aowner:Tcomponent);
begin
//on crée le panel
inherited create(Aowner);
setbounds(100,80,125,50);
//Images := ImgList;
//on initialise et on place la combobox
ComboBox1:=TComboBox.create(self);
ComboBox1.parent:=self;
ComboBox1.setbounds(4,27,117,21);
//On initialise l'imageliste
Imglist:=TImageList.create(self);
ImgList.name:=ImgListNom;
// Imglist.Name := 'MonImageList';
//fond gris
Shape1:=TShape.create(self);
Shape1.parent:=self;
Shape1.setBounds(0,0,125,24);
TitreFondCouleur:=$BABABA;
//On initialise et on place le label
Label1:=TLabel.create(self);
Label1.parent:=self;
Label1.setbounds(22,4,80,16);
Label1.AutoSize:=false;
Label1.alignment:=taCenter;
Label1.Caption:='titre';
Label1.Color:=$BABABA;
Label1.font.Size:=9;
Label1.Font.Style:=[Graphics.fsBold];
//On itnitialise et on place le cadre de l'image
Img:=TImage.create(self);
Img.parent:=self;
Img.setbounds(4,4,16,16);
Img.Visible:=true;
//On initialise la Led
LED1:=TJvTransLED.create(self);
LED1.parent :=self;
LED1.setbounds (110,7,10,10);
LED1.visible:=false; // sinon elle est tjr allumée
Shape1.Pen.Color:=$BABABA;
//On ne veut pas que le panel ait de caption
Caption:=' ';
end;
//on détruit
destructor TMonPanel94.Destroy;
begin
inherited destroy;
end;
end. |
Partager