unit1.pas

来自「看到很多手写控件」· PAS 代码 · 共 55 行

PAS
55
字号
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, OleServer, MSINKAUTLib_TLB, ExtCtrls, StdCtrls;

type
  TForm1 = class(TForm)
    InkCLT: TInkCollector;
    Memo1: TMemo;
    Panel1: TPanel;
    Button1: TButton;
    InkRecognizerContext1: TInkRecognizerContext;
    procedure FormCreate(Sender: TObject);
    procedure InkCLTStroke(ASender: TObject; const Cursor: IInkCursor;
      const Stroke: IInkStrokeDisp; var Cancel: WordBool);
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  InkCLT.hWnd := panel1.Handle;
  InkCLT.Enabled := true;
  InkCLT.DefaultDrawingAttributes.Color := clRed; // 墨水颜色
  InkCLT.DefaultDrawingAttributes.Width := 200; // 笔的宽度
end;

procedure TForm1.InkCLTStroke(ASender: TObject; const Cursor: IInkCursor;
  const Stroke: IInkStrokeDisp; var Cancel: WordBool);
begin
  Memo1.Lines.Clear;
  Memo1.Lines.Add(Stroke.Ink.Strokes.ToString);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  InkCLT.Ink.DeleteStrokes(InkCLT.Ink.Strokes);
  Panel1.Refresh;
end;

end.

⌨️ 快捷键说明

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