100分的难题!我用代码实现选中listbox中的一行,请问如何获得这一项的坐标!请各位大侠指教!
1, 是用itemindex的符值方法实现选中一行的,由于特殊原因的需要,不能使用mousedown等获得坐标。2,获得的坐标只要在选中的一行中就可以了

解决方案 »

  1.   

    function TListItem.GetPosition: TPoint;
      

  2.   

    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;
      

  3.   

    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);
      

  4.   

    你是不是弄错了,楼主要求listbox中,你怎么是listview呢?
      

  5.   

    西域浪子定义一个取ListBox坐标的函数。值得学习!谢了!
      

  6.   

    var p: TPoint;
    p := ListBox1.ItemRect(ListBox1.ItemIndex).TopLeft;
      

  7.   

    var Rect:TRect;
    Rect:=listbox1.ItemRect(ListBox1.ItemIndex);
      

  8.   

    西域浪子写的不对
    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;