本文整理自网络,侵删。
介绍如何在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组件中显示图像。
相关阅读 >>
tsqlconnection连接mysql(utf8)的问题
Delphi 如何让 tgpimage 直接从流中加载图片?
Delphi cxdbtreelist:最简单的节点图标添加方法
更多相关阅读请进入《Delphi》频道 >>