Mouse.cpp
上传用户:lulishicai
上传日期:2010-03-01
资源大小:13202k
文件大小:3k
源码类别:

Delphi/CppBuilder

开发平台:

C++ Builder

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "Mouse.h"
  5. //---------------------------------------------------------------------------
  6. #pragma package(smart_init)
  7. #pragma resource "*.dfm"
  8. TForm1 *Form1;
  9. Boolean start;
  10. Boolean move;
  11. int num;
  12. //声明变量
  13. //---------------------------------------------------------------------------
  14. __fastcall TForm1::TForm1(TComponent* Owner)
  15.         : TForm(Owner)
  16. {
  17. }
  18. //---------------------------------------------------------------------------
  19. void __fastcall TForm1::FormCreate(TObject *Sender)
  20. {
  21. start=false;
  22. move=false;
  23. //变量初始化
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TForm1::Button1Click(TObject *Sender)
  27. {
  28. start=true;
  29. //准备绘图
  30. }
  31. //---------------------------------------------------------------------------
  32. void __fastcall TForm1::Button2Click(TObject *Sender)
  33. {
  34. start=false;
  35. //结束绘图
  36. }
  37. //---------------------------------------------------------------------------
  38. void __fastcall TForm1::Button3Click(TObject *Sender)
  39. {
  40. Close();
  41. //结束程序运行
  42. }
  43. //---------------------------------------------------------------------------
  44. void __fastcall TForm1::RadioButton1Click(TObject *Sender)
  45. {
  46. num=1;
  47. //设置绘制鼠标轨迹的方式为圆
  48. }
  49. //---------------------------------------------------------------------------
  50. void __fastcall TForm1::RadioButton2Click(TObject *Sender)
  51. {
  52. num=2;
  53. //设置绘制鼠标轨迹的方式为矩形
  54. }
  55. //---------------------------------------------------------------------------
  56. void __fastcall TForm1::RadioButton3Click(TObject *Sender)
  57. {
  58. num=3;
  59. //设置绘制鼠标轨迹的方式为直线
  60. }
  61. //---------------------------------------------------------------------------
  62. void __fastcall TForm1::RadioButton4Click(TObject *Sender)
  63. {
  64. num=4;
  65. //设置绘制鼠标轨迹的方式为椭圆
  66. }
  67. //---------------------------------------------------------------------------
  68. void __fastcall TForm1::Image1MouseDown(TObject *Sender,
  69.       TMouseButton Button, TShiftState Shift, int X, int Y)
  70. {
  71. move=true;
  72. //开始绘图
  73. }
  74. //---------------------------------------------------------------------------
  75. void __fastcall TForm1::Image1MouseMove(TObject *Sender, TShiftState Shift,
  76.       int X, int Y)
  77. {
  78. if (start)
  79.    {
  80.    if (move)
  81.       {
  82.       if (num==1)
  83.          Form1->Image1->Canvas->Ellipse(X-5,Y-5,X+5,Y+5);
  84.          //以圆的形式跟踪鼠标轨迹
  85.       else if (num==2)
  86.          Form1->Image1->Canvas->Rectangle(X-5,Y-5,X+5,Y+5);
  87.          //以矩形的形式跟踪鼠标轨迹
  88.       else if (num==3)
  89.          Form1->Image1->Canvas->LineTo(X,Y);
  90.          //以直线的形式跟踪鼠标轨迹
  91.       else if (num==4)
  92.          Form1->Image1->Canvas->Ellipse(X-5,Y-2,X+5,Y+2);
  93.          //以椭圆的形式跟踪鼠标轨迹
  94.       }
  95.     }
  96. //按照鼠标的运动轨迹绘图
  97. }
  98. //---------------------------------------------------------------------------
  99. void __fastcall TForm1::Image1MouseUp(TObject *Sender, TMouseButton Button,
  100.       TShiftState Shift, int X, int Y)
  101. {
  102. move=false;
  103. //结束绘图
  104. }
  105. //---------------------------------------------------------------------------