怎样获取鼠标在memo中点击时的坐标位置:X,Y,Z

解决方案 »

  1.   

    unit ClientToScreenU;interfaceuses
      Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
      StdCtrls;type                         
      TForm1 = class(TForm)
        Memo1: TMemo;
        Label1: TLabel;
        Label2: TLabel;
        Label3: TLabel;
        procedure Memo1MouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.DFM}procedure TForm1.Memo1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    var
      Coords: TPoint;    // holds the point being converted
    begin
      {indicate the clicked coordinates relative to the child window}
      Label1.Caption := 'Memo Coordinates: '+IntToStr(X)+', '+IntToStr(Y);  {convert these coordinates into screen coordinates}
      Coords := Point(X, Y);
      Windows.ClientToScreen(Memo1.Handle, Coords);  {display the clicked coordinates relative to the screen}
      Label2.Caption := 'Screen Coordinates: '+IntToStr(Coords.X)+', '+
                        IntToStr(Coords.Y);  {convert the coordinates into window client coordinates}
      Windows.ScreenToClient(Form1.Handle, Coords);  {display the clicked coordinates relative to the client area of the window}
      Label3.Caption := 'Form Coordinates: '+IntToStr(Coords.X)+', '+
                        IntToStr(Coords.Y);
    end;end.
      

  2.   

    那就是光标位置
    var p:Tpoint;
    GetCaretPos(p);