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 分割文件合并文件的函数

Delphi 中的字符串

Delphi 泛型数组 strsplit 字符串分割

tsqlconnection连接mysql(utf8)的问题

Delphi tdictionary使用范例

Delphi pchar与string互转

Delphi 串口控制继电器

Delphi 如何让 tgpimage 直接从流中加载图片?

Delphi 取windows登录用户名

Delphi cxdbtreelist:最简单的节点图标添加方法

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



打赏

取消

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

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

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

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

评论

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