Иллюстрированный самоучитель по Delphi 7 для профессионалов

Управление мышью

Листинг 27.2. Модуль главной формы проекта DemoMouse.

unit Main;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ExtCTRLs, ComCTRLs;
type
TMainForm = class(TForm) ColorDlg: TColorDialog;
StatusBar: TStatusBar; Timer: TTimer;
procedure FormMouseDown(Sender: TObject;
Button: TMouseButton;
SHIFT: TSHIFTState; X, Y: Integer);
procedure FormMouseUp(Sender: TObject;
Button: TMouseButton;
SHIFT: TSHIFTState; X, Y: Integer);
procedure FormMouseMove(Sender: TObject; SHIFT: TSHIFTState; X, Y: Integer);
procedure TimerTimer(Sender: TObject);
private
MouseRect: TRect;
IsDown: Boolean;
RectColor: TColor;
public
{ Public declarations }
end;
var
MainForm: TMainForm;
implementation {$R *.DFM}
procedure TMainForm.FormMouseDown(Sender: TObject; Button: TMouseButton;
SHIFT: TSHIFTState; X, Y: Integer);
begin
if Button = mbLeft then with MouseRect do
begin
IsDown: = True; Left: = X; Top: = Y; Right: = X; Bottom: = Y;
Canvas.Pen.Color: = RectColor;
end;
if (Button = mbRight) and ColorDlg.Execute then RectColor: = ColorDlg.Color;
end;
procedure TMainForm.FormMouseUp(Sender: TObject;
Button: TMouseButton;
SHIFT: TSHIFTState; X, Y: Integer);
begin
IsDown: = False;
Canvas.Pen.Color: = Color;
with MouseRect do
Canvas.Polyline([Point(Left, Top), Point(Right, Top), Point(Right,
Bottom), Point(Left, Bottom), Point(Left, Top)]);
with StatusBar do
begin
Panels[4].Text: = ''; Panels [5].Text: = ";
end;
end;
procedure TMainForm.FonnMouseMove(Sender: TObject; SHIFT: TSHIFTState; X,
Y: Integer);
begin
with StatusBar do
begin
Panels[2].Text: = 'X: ' + IntToStr(X);
Panels[3].Text: = 'Y: ' + IntToStr(Y);
end;
if Not IsDown then Exit; Canvas.Pen.Color: = Color; with mouserect do
begin
Canvas.Polyline([Point(Left, Top), Point(Right, Top),
Point(Right, Bottom), Point(Left, Bottom), Point(Left, Top)]);
Right: = X;
Bottom: = Y;
Canvas.Pen.Color: = RectColor;
Canvas.Polyline([Point(Left, Top), Point(Right, Top),
Point(Right, Bottom), Point(Left, Bottom), Point(Left, Top)]);
end;
with StatusBar do begin
Panels [4].Text: = 'IHwpMHa: ' + IntToStr(Abs(MouseRect.Right – MouseRect.Left));
Panels[5].Text: = 'BacoTa: ' + IntToStr(Abs(MouseRect.Bottom – MouseRect.Top));
end; end;
procedure TMainForm.TimerTimer(Sender: TObject);
begin
with StatusBar do
begin
Panels[0].Text: = 'flaTa: ' + DateToStr(Now); Panels[1].Text: = 'BpeMH: ' + TimeToStr(Now);
end;
end;
end.
Если Вы заметили ошибку, выделите, пожалуйста, необходимый текст и нажмите CTRL + Enter, чтобы сообщить об этом редактору.