ToolObject.cs
上传用户:sxsgcs
上传日期:2013-10-21
资源大小:110k
文件大小:2k
源码类别:

CAD

开发平台:

C#

  1. using System;
  2. using System.Windows.Forms;
  3. using System.Drawing;
  4. namespace DrawTools
  5. {
  6. /// <summary>
  7. /// Base class for all tools which create new graphic object
  8. /// </summary>
  9. abstract class ToolObject : DrawTools.Tool
  10. {
  11.         private Cursor cursor;
  12.         /// <summary>
  13.         /// Tool cursor.
  14.         /// </summary>
  15.         protected Cursor Cursor
  16.         {
  17.             get
  18.             {
  19.                 return cursor;
  20.             }
  21.             set
  22.             {
  23.                 cursor = value;
  24.             }
  25.         }
  26.         /// <summary>
  27.         /// Left mouse is released.
  28.         /// New object is created and resized.
  29.         /// </summary>
  30.         /// <param name="drawArea"></param>
  31.         /// <param name="e"></param>
  32.         public override void OnMouseUp(DrawArea drawArea, MouseEventArgs e)
  33.         {
  34.             drawArea.GraphicsList[0].Normalize();
  35.             drawArea.AddCommandToHistory(new CommandAdd(drawArea.GraphicsList[0]));
  36.             drawArea.ActiveTool = DrawArea.DrawToolType.Pointer;
  37.             drawArea.Capture = false;
  38.             drawArea.Refresh();
  39.         }
  40.         /// <summary>
  41.         /// Add new object to draw area.
  42.         /// Function is called when user left-clicks draw area,
  43.         /// and one of ToolObject-derived tools is active.
  44.         /// </summary>
  45.         /// <param name="drawArea"></param>
  46.         /// <param name="o"></param>
  47.         protected void AddNewObject(DrawArea drawArea, DrawObject o)
  48.         {
  49.             drawArea.GraphicsList.UnselectAll();
  50.             o.Selected = true;
  51.             drawArea.GraphicsList.Add(o);
  52.             drawArea.Capture = true;
  53.             drawArea.Refresh();
  54.             drawArea.SetDirty();
  55.         }
  56. }
  57. }