begin process at 2008 08 20 15:03:22
1 228 884 membres
250 nouveaux aujourd'hui
14 258 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

UTILISER UNE IMAGE DANS LE CANVAS D'UNE LISTBOX


Information sur la source

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é: 2 541 / 311

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

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10

Commentaire sur cette source (0)
Ajouter un commentaire et/ou une note

Description

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 :)

Pour les "Membres Club", vous pouvez télécharger directement un fichier contenu dans le zip sans télécharger le zip en entier !

Télécharger le zip

    Aucun commentaire pour le moment.

Ajouter un commentaire

Pub



Appels d'offres

CalendriCode

Août 2008
LMMJVSD
    123
45678910
11121314151617
18192021222324
25262728293031

VS Express FR Gratuit !

VS Express en français et 100% gratuit !

Boutique

Boutique de goodies CodeS-SourceS