procedure TForm1.ListBox1Click(Sender: TObject); var x,y:integer; begin x:=ListBox1.top; y:=ListBox1.Left+ListBox1.ItemHeight*(ListBox1.ItemIndex+1); Label1.Caption:=inttostr(y); end;
procedure TForm1.Button1Click(Sender: TObject); var p : TPoint; begin ListView1.Items[1].Selected := True; p := ListView1.Items[1].GetPosition; Label1.Caption := inttostr(p.x)+':'+inttostr(p.y);
你是不是弄错了,楼主要求listbox中,你怎么是listview呢?
西域浪子定义一个取ListBox坐标的函数。值得学习!谢了!
var p: TPoint; p := ListBox1.ItemRect(ListBox1.ItemIndex).TopLeft;
var Rect:TRect; Rect:=listbox1.ItemRect(ListBox1.ItemIndex);
西域浪子写的不对 procedure TtestForm.ListBox1Click(Sender: TObject); var i,x1,y1,x,y:integer; begin x1:=ListBox1.Left;//listBox1的横坐标 y1:=listBox1.Top;//listBox1的纵坐标 y:=listBox1.ItemIndex*ListBox1.ItemHeight+y1;//纵坐标 x:=x1;//横坐标,如果位置稍微有些偏差,可以加1、2、等自己在调整一下就行了 showmessage(intTostr(x)+' '+intToStr(y)); end;
var x,y:integer;
begin
x:=ListBox1.top;
y:=ListBox1.Left+ListBox1.ItemHeight*(ListBox1.ItemIndex+1);
Label1.Caption:=inttostr(y);
end;
var
p : TPoint;
begin
ListView1.Items[1].Selected := True;
p := ListView1.Items[1].GetPosition;
Label1.Caption := inttostr(p.x)+':'+inttostr(p.y);
p := ListBox1.ItemRect(ListBox1.ItemIndex).TopLeft;
Rect:=listbox1.ItemRect(ListBox1.ItemIndex);
procedure TtestForm.ListBox1Click(Sender: TObject);
var i,x1,y1,x,y:integer;
begin
x1:=ListBox1.Left;//listBox1的横坐标
y1:=listBox1.Top;//listBox1的纵坐标
y:=listBox1.ItemIndex*ListBox1.ItemHeight+y1;//纵坐标
x:=x1;//横坐标,如果位置稍微有些偏差,可以加1、2、等自己在调整一下就行了
showmessage(intTostr(x)+' '+intToStr(y));
end;