Delphi XE8在Firemonkey TListBox中显示图像


本文整理自网络,侵删。

 

介绍如何在TListBoxItem的OnList事件中显示以及如何通过在TListBoxItem上放置TImage组件进行显示。

如何在TListBoxItem的OnPaint事件中显示
在窗体上放置一个TButton组件和一个TListBox组件。

描述TButton组件的OnClick事件。

procedure TForm2.Button1Click(Sender: TObject);
var
  Item: TListBoxItem;
begin
  Item := TListBoxItem.Create(nil);
  Item.Parent := ListBox1;
  Item.Height := 200;
  Item.OnPaint := ListBoxItemPaint;
end;
当按下按钮时,一个项目将添加到ListBox1。

ListBox1的项目是使用表单的ListBoxItemPaint方法绘制的。

将ListBoxItemPaint方法添加到窗体。

type
  TForm2 = class(TForm)
    Button1: TButton;
    ListBox1: TListBox;
    procedure Button1Click(Sender: TObject);
  private
    { private 宣言 }
    procedure ListBoxItemPaint(Sender: TObject; Canvas: TCanvas;
      const ARect: TRectF);
  public
    { public 宣言 }
  end;
使用ListBoxItemPaint方法绘制图像。

procedure TForm2.ListBoxItemPaint(Sender: TObject; Canvas: TCanvas;
  const ARect: TRectF);
const
  IMAGEFILE_PATH =
    'C:\Program Files (x86)\Embarcadero\Studio\16.0\Images\Splash\256Color\CHEMICAL.BMP';
var
  Bitmap: TBitmap;
  SrcRect, DstRect: TRectF;
begin
  Bitmap := TBitmap.Create;
  Bitmap.LoadFromFile(IMAGEFILE_PATH);

  SrcRect.Left := 0;
  SrcRect.Top := 0;
  SrcRect.Width := Bitmap.Width;
  SrcRect.Height := Bitmap.Height;

  DstRect.Left := 0;
  DstRect.Top := 0;
  DstRect.Width := Bitmap.Width;
  DstRect.Height := Bitmap.Height;

  Canvas.DrawBitmap(Bitmap, SrcRect, DstRect, 1.0, True);
  Bitmap.Free;
end;
listbox01

如何将TImage组件放置在TListBoxItem的顶部
在窗体上放置一个TButton组件和一个TListBox组件。

描述TButton组件的OnClick事件。

procedure TForm2.Button1Click(Sender: TObject);
const
  IMAGEFILE_PATH =
    'C:\Program Files (x86)\Embarcadero\Studio\16.0\Images\Splash\256Color\CHEMICAL.BMP';
var
  Item: TListBoxItem;
  Image: TImage;
begin
  Item := TListBoxItem.Create(nil);
  Item.Parent := ListBox1;
  Item.Height := 200;

  Image := TImage.Create(Item);
  Image.Parent := Item;
  Image.Width := 240;
  Image.Height := 180;
  Image.Bitmap.LoadFromFile(IMAGEFILE_PATH);
end;
当按下按钮时,一个项目将添加到ListBox1。

将TImage组件放在添加的项目上,并在TImage组件中显示图像。

相关阅读 >>

Delphi treeview节点展开与折叠

Delphi synedit1 synmemo1 显示行号

Delphi实现获取密码框中的密码

Delphi 几个日期操作

Delphi 实现软件版验证码

Delphi listbox用canvas属性绘图

Delphi 几种程序自杀的方法

Delphi里实现彩色图片转为黑白图像的功能

Delphi idhttp多线程下载

Delphi 链接文件名合并

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...