zoukankan      html  css  js  c++  java
  • 鼠标选取图象的实现

    type
      TForm1 = class(TForm)
        procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
        procedure FormMouseMove(Sender: TObject; Shift: TShiftState; X,
          Y: Integer);
        procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
          Shift: TShiftState; X, Y: Integer);
      private
        { Private declarations }
        Capturing : bool;
        Captured : bool;
        StartPlace : TPoint;
        EndPlace : TPoint;
      public
        { Public declarations }
      end;
    
    var
      Form1: TForm1;
    
    implementation
    
    {$R *.DFM}
    
    function MakeRect(Pt1 : TPoint;
                      Pt2 : TPoint) : TRect;
    begin
      if pt1.x < pt2.x then begin
        Result.Left := pt1.x;
        Result.Right := pt2.x;
      end else begin
        Result.Left := pt2.x;
        Result.Right := pt1.x;
      end;
      if pt1.y < pt2.y then begin
        Result.Top := pt1.y;
        Result.Bottom := pt2.y;
      end else begin
        Result.Top := pt2.y;
        Result.Bottom := pt1.y;
      end;
    end;
    
    procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      if Captured then
        DrawFocusRect(Form1.Canvas.Handle,
                      MakeRect(StartPlace,
                               EndPlace));
      StartPlace.x := X;
      StartPlace.y := Y;
      EndPlace.x := X;
      EndPlace.y := Y;
      DrawFocusRect(Form1.Canvas.Handle,
                    MakeRect(StartPlace,
                             EndPlace));
      Capturing := true;
      Captured := true;
    end;
    
    procedure TForm1.FormMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    begin
      if Capturing then begin
        DrawFocusRect(Form1.Canvas.Handle,
                      MakeRect(StartPlace,
                               EndPlace));
        EndPlace.x := X;
        EndPlace.y := Y;
        DrawFocusRect(Form1.Canvas.Handle,
                      MakeRect(StartPlace,
                               EndPlace));
      end;
    
    end;
    
    procedure TForm1.FormMouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    begin
      Capturing := false;
    end;
  • 相关阅读:
    js面试题-----页面布局
    js面试题-----原型和原型链
    js面试题-----运行环境
    js面试题-----开发环境
    js面试题-----事件及ajax
    js面试题-----DOM操作和BOM操作
    js面试题-----异步和单线程及其他知识点
    js面试题-----作用域与闭包
    js面试题-----变量类型和计算
    js学习总结----webapp之使用less构建响应式布局
  • 原文地址:https://www.cnblogs.com/yzryc/p/6373629.html
Copyright © 2011-2022 走看看