clienttoscreenu.pas

来自「Delphi Win32核心API参考光盘」· PAS 代码 · 共 55 行

PAS
55
字号
unit ClientToScreenU;

interface

uses
  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.

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?