检测已单击/按下ListViewItem的位置 [英] Detect where ListViewItem has been clicked/pressed

查看:73
本文介绍了检测已单击/按下ListViewItem的位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Delphi XE8中,使用Firemonkey TListView。

In Delphi XE8 using a Firemonkey TListView.

我有一个ListView,其中包含约5个项目。每个项目中都有一个图像。

I have a ListView with about 5 items in it. Each item has an image within them.

如何检测到何时单击/按下图像?

How would one detect when the image is clicked/pressed?.

我一直在寻找过程:

OnItemClickEx

但是我不知道如何使用它。不确定这是否是我需要使用的。

But I do not understand how to use it. Wasn't sure if this is what I need to use or not.

任何帮助都会很棒。

谢谢

推荐答案

设置Listview项图像对象属性...。

Set Listview item image object properties....

procedure TForm1.OnFormCreate(Sender:TObject)
begin
  ListView1.ItemAppearanceObjects.ItemObjects.Image.Align :=  TListItemAlign.Leading;
  ListView1.ItemAppearanceObjects.ItemObjects.Image.VertAlign := TListItemAlign.Center;
  ListView1.ItemAppearanceObjects.ItemObjects.Image.PlaceOffset.X := 370;
end;

然后在ItemClickEx过程中执行以下操作:

Then in the ItemClickEx procedure I did the following:

procedure TForm1.ListView1ItemClickEx(const Sender: TObject;
ItemIndex: Integer; const LocalClickPos: TPointF;
const ItemObject: TListItemObject);
begin
 if (LocalClickPos.X > ListView1.ItemAppearanceObjects.ItemObjects.Image.PlaceOffset.X) and
 (LocalClickPos.X < (ListView1.ItemAppearanceObjects.ItemObjects.Image.PlaceOffset.X + ListView1.ItemAppearanceObjects.ItemObjects.Image.Width)) and
 (LocalClickPos.Y > ListView1.ItemAppearanceObjects.ItemObjects.Image.PlaceOffset.Y) and
 (LocalClickPos.Y < (ListView1.ItemAppearanceObjects.ItemObjects.Image.PlaceOffset.Y + ListView1.ItemAppearanceObjects.ItemObjects.Image.Height)) then
  begin
    ShowMessage('Image Pressed!;)
  end;
end;

这篇关于检测已单击/按下ListViewItem的位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆