begin process at 2010 02 10 08:50:07
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Trucs & Astuces

 > UTILISER UNE IMAGE DANS LE CANVAS D'UNE LISTBOX

UTILISER UNE IMAGE DANS LE CANVAS D'UNE LISTBOX


 Information sur la source

Note :
9,33 / 10 - par 3 personnes
9,33 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Trucs & Astuces Niveau :Débutant Date de création :09/07/2004 Date de mise à jour :09/07/2004 03:49:36 Vu / téléchargé :3 243 / 390

Auteur : Programmeur1987

Ecrire un message privé
Site perso
Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

 Description

Cliquez pour voir la capture en taille normale
J'ai cherché longuement a plusieur endroit comment ajouter une image dans le canvas d'une ListBox.  C'est simple lorsqu'il doive défiler une apres l'autre avec le simple Index de la ListBox utiliser, Mais lorsqu'il est question d'inséré une image aléatoire au canvas, si la méthode employer n'est pas Correct, tout les autres images de change pour la derniere Ajouter.


P.s.  Ne pas faire attention a mon orthographe des commentaires suis sérieusement nul en francais.

Source

  • unit Unit1;
  • interface
  • uses
  • Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  • Dialogs, ImgList, Buttons, StdCtrls;
  • type
  • TForm1 = class(TForm)
  • ListBox3: TListBox;
  • SpeedButton1: TSpeedButton;
  • ImageNiveau: TImageList;
  • Label1: TLabel;
  • Edit1: TEdit;
  • Label2: TLabel;
  • procedure ListBox3MeasureItem(Control: TWinControl; Index: Integer;
  • var Height: Integer);
  • procedure ListBox3DrawItem(Control: TWinControl; Index: Integer;
  • Rect: TRect; State: TOwnerDrawState);
  • procedure SpeedButton1Click(Sender: TObject);
  • procedure FormCreate(Sender: TObject);
  • private
  • { Déclarations privées }
  • public
  • PicNiveau : Integer;
  • lstimage : array of 0..5-1;
  • Texte:String;
  • LongeurLst:integer;
  • { Déclarations publiques }
  • end;
  • var
  • Form1: TForm1;
  • implementation
  • {$R *.dfm}
  • procedure TForm1.ListBox3MeasureItem(Control: TWinControl; Index: Integer;
  • var Height: Integer);
  • begin
  • //on ajuste la grosseur de l'item pour accueillir l'item
  • height := ImageNiveau.Height + 4;
  • end;
  • procedure TForm1.ListBox3DrawItem(Control: TWinControl; Index: Integer;
  • Rect: TRect; State: TOwnerDrawState);
  • var
  • CenterText : integer;
  • begin
  • With ListBox3.Canvas do
  • begin
  • ListBox3.Canvas.FillRect (rect);
  • CenterText := ( rect.Bottom - rect.Top - ListBox3.Canvas.TextHeight(text)) div 2 ;
  • ListBox3.Canvas.TextOut (rect.left + ImageNiveau.Width + 8 , rect.Top + CenterText,
  • ListBox3.Items.Strings[Index]);
  • // on donne la valeur a aller chercher dans liste d'image
  • LstImage[LongeurLst-1]:= strtoint(Edit1.text);
  • //on print l'image dans le canvas
  • ImageNiveau.Draw(ListBox3.Canvas,rect.Left + 4, rect.Top + 4, LstImage[Index]);
  • end;
  • end;
  • procedure TForm1.SpeedButton1Click(Sender: TObject);
  • begin
  • //On stock la donner
  • inc(LongeurLst);
  • SetLength(LstImage,LongeurLst);
  • //on ajouter la donner
  • ListBox3.AddItem('Nouvel Item',nil);
  • end;
  • procedure TForm1.FormCreate(Sender: TObject);
  • begin
  • //on donne une valeur a l'integer LongeurLst
  • LongeurLst :=0;
  • end;
  • end.
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ImgList, Buttons, StdCtrls;


type
  TForm1 = class(TForm)
    ListBox3: TListBox;
    SpeedButton1: TSpeedButton;
    ImageNiveau: TImageList;
    Label1: TLabel;
    Edit1: TEdit;
    Label2: TLabel;
    procedure ListBox3MeasureItem(Control: TWinControl; Index: Integer;
      var Height: Integer);
    procedure ListBox3DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure SpeedButton1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Déclarations privées }
  public
  PicNiveau : Integer;
  lstimage : array of 0..5-1;
  Texte:String;
  LongeurLst:integer;
    { Déclarations publiques }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ListBox3MeasureItem(Control: TWinControl; Index: Integer;
  var Height: Integer);
begin
//on ajuste la grosseur de l'item pour accueillir l'item
height := ImageNiveau.Height + 4; 
end;

procedure TForm1.ListBox3DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
var
CenterText : integer;
begin
With ListBox3.Canvas do
begin
ListBox3.Canvas.FillRect (rect);
CenterText := ( rect.Bottom - rect.Top - ListBox3.Canvas.TextHeight(text)) div 2 ;
ListBox3.Canvas.TextOut (rect.left + ImageNiveau.Width + 8 , rect.Top + CenterText,
ListBox3.Items.Strings[Index]);
// on donne la valeur a aller chercher dans liste d'image
LstImage[LongeurLst-1]:= strtoint(Edit1.text);
//on print l'image dans le canvas
ImageNiveau.Draw(ListBox3.Canvas,rect.Left + 4, rect.Top + 4,  LstImage[Index]);
end;
end;

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
//On stock la donner
inc(LongeurLst);
SetLength(LstImage,LongeurLst);
//on ajouter la donner
ListBox3.AddItem('Nouvel Item',nil);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
//on donne une valeur a l'integer LongeurLst
LongeurLst :=0;
end;

end.

 Conclusion

Un ptit merci a ZeroCool qui a refiler un coup de main pour me donner l'idée d'utiliser un 2eme Index :)


 Fichier Zip

Les Membres Club peuvent télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip


 Sources de la même categorie

Source avec Zip Source avec une capture UTILISER UNE DLL INCLUSE EN RESSOURCES par Bacterius
Source avec Zip Source avec une capture IMAGE DANS UN TDBGRID par HAFTARIFOUAD
Source avec Zip Source avec une capture [ASTUCE] COMMENT VOIR UN ITEM, D'UNE LISTBOX, TRONQUÉ DANS U... par cirec
Source avec Zip Source avec une capture MESSAGEDLG PERSONNALISÉ par HAFTARIFOUAD
Source avec Zip Source avec une capture COMMENT DESSINER SUR UN TCANVAS LE TEXTE D'UNE FORMULE CHIMI... par pseudo3

Commentaires et avis

Aucun commentaire pour le moment.

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Février 2010
LMMJVSD
1234567
891011121314
15161718192021
22232425262728

Consulter la suite du CalendriCode

 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,515 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales