cgelement.cs

来自「苏金明编写的《用VB.NET和VC#.NET开发交互式CAD系统》一书的源代码」· CS 代码 · 共 88 行

CS
88
字号
using System;
using System.Drawing;
using System.Drawing.Drawing2D;

namespace VCSharp
{
	/// <summary>
	/// CGElement 的摘要说明。
	/// </summary>
	public abstract class CGElement
	{

		private int m_Color;
		private int m_Style;
		private int m_Width;

		public int Color
		{
			get{return m_Color;}
			set{m_Color=value;}
		}

		public int Style
		{
			get{return m_Style;}
			set{m_Style=value;}
		}
  
		public int Width
		{
			get{return m_Width;}
			set{m_Width=value;}
		}

		public CGElement()
		{
			Init();
		}

	    //初始化图元
	   protected void Init()
       {
        	m_Style=0;
	        m_Width=1;
			m_Color=0;
		}
		
		//绘制图元
		abstract public void Draw(Graphics g,DrawMode aDrawMode);

		//根据不同的绘图模式设置不同的绘图参数
		public int[] DrawSettings(IntPtr hdc,DrawMode aDrawMode)
		{
			switch(aDrawMode)
			{
				case DrawMode.Normal:
		            Win32API.SetROP2(hdc, 13);
	                m_Style = 0;
	                m_Width = 1;
	                m_Color =0;
					break;
	            case DrawMode.Selec:
	                Win32API.SetROP2(hdc, 13);
	                m_Style = 1;
	                m_Width = 1;
	                m_Color =255;
					break;
	            case DrawMode.Drag:
	                Win32API.SetROP2(hdc, 10);
	                m_Style = 0;
	                m_Width = 1;
	                m_Color =16711680;
					break;
	            case DrawMode.Delete:
	                Win32API.SetROP2(hdc, 13);
	                m_Style = 0;
	                m_Width = 1;
	                m_Color =16777215;
					break;
	       }

			int[] penPara={m_Style,m_Width,m_Color};

		   return penPara;
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?