各位大虾好!!!小弟想问一下在ListView中点击子项后怎样捕获鼠标在ListView内的坐标,上次在这里问过,但没有合适的答案,想自己探索一下,但还是摸不着头脑,实在没有办法了,还请各位大虾帮助一下,先谢谢了。

解决方案 »

  1.   

    下面程序在D7下测试通过
    ------------------------------------
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs, StdCtrls, ComCtrls;type
      TForm1 = class(TForm)
        ListView1: TListView;
        Button1: TButton;
        procedure Button1Click(Sender: TObject);
        procedure ListView1MouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.Button1Click(Sender: TObject);
    VAR MyItem:TListItem;
        I:Integer;
    begin
        for I:=1 to 10 do
        begin
            MyItem:=listView1.Items.Add;
            MyItem.Caption:='项目'+IntToStr(I);
        end;
    end;procedure TForm1.ListView1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
        if listview1.SelCount <> 0 then
        begin
            showmessage('x:'+IntToStr(x)+#13+'y:'+IntToStr(y));
        end;
    end;end.
      

  2.   

    思路:在鼠标点下的时候判断是否有项目被选中,如果有的话,就输出x,y的值
          button1用来创建10个items
      

  3.   

    对不起,小弟说错话了,应该是:“能不能用消息机制来实现”,多了个‘我’字,请大虾们见谅,小弟正在学消息,本来是在学VCL的,没有办法,都要学的。