Mouse.cpp
上传用户:lulishicai
上传日期:2010-03-01
资源大小:13202k
文件大小:3k
源码类别:
Delphi/CppBuilder
开发平台:
C++ Builder
- //---------------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include "Mouse.h"
- //---------------------------------------------------------------------------
- #pragma package(smart_init)
- #pragma resource "*.dfm"
- TForm1 *Form1;
- Boolean start;
- Boolean move;
- int num;
- //声明变量
- //---------------------------------------------------------------------------
- __fastcall TForm1::TForm1(TComponent* Owner)
- : TForm(Owner)
- {
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::FormCreate(TObject *Sender)
- {
- start=false;
- move=false;
- //变量初始化
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- start=true;
- //准备绘图
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button2Click(TObject *Sender)
- {
- start=false;
- //结束绘图
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Button3Click(TObject *Sender)
- {
- Close();
- //结束程序运行
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::RadioButton1Click(TObject *Sender)
- {
- num=1;
- //设置绘制鼠标轨迹的方式为圆
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::RadioButton2Click(TObject *Sender)
- {
- num=2;
- //设置绘制鼠标轨迹的方式为矩形
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::RadioButton3Click(TObject *Sender)
- {
- num=3;
- //设置绘制鼠标轨迹的方式为直线
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::RadioButton4Click(TObject *Sender)
- {
- num=4;
- //设置绘制鼠标轨迹的方式为椭圆
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Image1MouseDown(TObject *Sender,
- TMouseButton Button, TShiftState Shift, int X, int Y)
- {
- move=true;
- //开始绘图
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
- int X, int Y)
- {
- if (start)
- {
- if (move)
- {
- if (num==1)
- Form1->Image1->Canvas->Ellipse(X-5,Y-5,X+5,Y+5);
- //以圆的形式跟踪鼠标轨迹
- else if (num==2)
- Form1->Image1->Canvas->Rectangle(X-5,Y-5,X+5,Y+5);
- //以矩形的形式跟踪鼠标轨迹
- else if (num==3)
- Form1->Image1->Canvas->LineTo(X,Y);
- //以直线的形式跟踪鼠标轨迹
- else if (num==4)
- Form1->Image1->Canvas->Ellipse(X-5,Y-2,X+5,Y+2);
- //以椭圆的形式跟踪鼠标轨迹
- }
- }
- //按照鼠标的运动轨迹绘图
- }
- //---------------------------------------------------------------------------
- void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button,
- TShiftState Shift, int X, int Y)
- {
- move=false;
- //结束绘图
- }
- //---------------------------------------------------------------------------