Недавно добавленные исходники

•  DeLiKaTeS Tetris (Тетрис)  4 722

•  TDictionary Custom Sort  6 724

•  Fast Watermark Sources  6 507

•  3D Designer  9 445

•  Sik Screen Capture  6 838

•  Patch Maker  7 288

•  Айболит (remote control)  7 230

•  ListBox Drag & Drop  6 090

•  Доска для игры Реверси  97 825

•  Графические эффекты  7 406

•  Рисование по маске  6 701

•  Перетаскивание изображений  5 556

•  Canvas Drawing  5 941

•  Рисование Луны  5 717

•  Поворот изображения  5 179

•  Рисование стержней  3 782

•  Paint on Shape  2 962

•  Генератор кроссвордов  3 904

•  Головоломка Paletto  3 103

•  Теорема Монжа об окружностях  3 913

•  Пазл Numbrix  2 577

•  Заборы и коммивояжеры  3 371

•  Игра HIP  2 312

•  Игра Go (Го)  2 211

•  Симулятор лифта  2 620

•  Программа укладки плитки  2 203

•  Генератор лабиринта  2 719

•  Проверка числового ввода  2 360

•  HEX View  2 696

•  Физический маятник  2 373

 
скрыть

Рисование картинок в TListBox



Оформил: DeeCo

{ Create a TImage on your Formular and assign a bitmap }
 { Create a TListbox on your Formular }

 type
   TForm1 = class(TForm)
     ListBox1: TListBox;
     Image1: TImage;
     procedure FormCreate(Sender: TObject);
     procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
       Rect: TRect; State: TOwnerDrawState);
     procedure ListBox1MeasureItem(Control: TWinControl; Index: Integer;
       var Height: Integer);
   private
     {...}
   public
     {...}
   end;

 procedure TForm1.FormCreate(Sender: TObject);
 begin
   with ListBox1.Items do
   begin
     Clear;
     ListBox1.Style := lbOwnerDrawVariable;
     AddObject('Bitmap1', Image1.Picture.Bitmap);
     AddObject('Bitmap2', Image2.Picture.Bitmap);
     AddObject('Bitmap3', Image3.Picture.Bitmap);
   end;
 end;

 procedure CenterText(Cnv: TCanvas; Rect: TRect; S: string);
 var
    X, Y: Integer;
 begin
   X := (Rect.Right + Rect.Left - Cnv.TextWidth(S)) div 2;
   Y := (Rect.Bottom + Rect.Top - Cnv.TextHeight(S)) div 2;
   Cnv.TextOut(X, Y, S);
 end;

 procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
   Rect: TRect; State: TOwnerDrawState);
 var
    Bitmap: TBitmap;
 begin
   with ListBox1 do
   begin
     Canvas.FillRect(Rect);
     if Items.Objects[Index] <> nil then
     begin
       Bitmap := Items.Objects[Index] as TBitmap;
       Canvas.BrushCopy(Bounds(Rect.Left + 2, Rect.Top + 2,
         Bitmap.Width, Bitmap.Height), Bitmap, Bounds(0, 0, Bitmap.Width,
         Bitmap.Height), Bitmap.Canvas.Pixels[0, Bitmap.Height - 1]);
     end;
     Rect.Left   := Rect.Left + Bitmap.Width + 4;
     Rect.Bottom := Rect.Top + Bitmap.Height + 4;
     CenterText(Canvas, Rect, Items.Strings[Index]);
   end;
 end;

 procedure TForm1.ListBox1MeasureItem(Control: TWinControl; Index: Integer;
   var Height: Integer);
 begin
   if Index = 0 then Height := Image1.Height + 4;
 end;

Copyright © 2004-2025 "Delphi Sources" by BrokenByte Software. Delphi World FAQ

Группа ВКонтакте