⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ctext.cs

📁 苏金明编写的《用VB.NET和VC#.NET开发交互式CAD系统》一书的源代码
💻 CS
字号:
using System;
using System.Drawing;
using System.Drawing.Drawing2D;

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

	    private Font m_Font;
	    private PointF m_Pos;
	    private string m_Content;
	    private float m_Size;
	    private float m_Angle;
	    private Color m_Color;
	    private FontStyle m_Style;
		Module m=new Module();

	    //字体属性
		public Font Font
		{
			get{return m_Font;}
			set{m_Font = value;}
		}

	    //位置属性
		public PointF Pos
		{
			get{return m_Pos;}
			set{m_Pos = value;}
		}

	    //大小属性
		public float Size
		{
			get{return m_Size;}
			set{m_Size = value;}
		}

	    //内容属性
		public string Content
		{
			get{return m_Content;}
			set{m_Content = value;}
		}

	    //旋转角度属性
		public float Angle
		{
			get{return m_Angle;}
			set{m_Angle = value;}
		}

	    //颜色属性
		new public Color Color
		{
			get{return m_Color;}
			set{m_Color = value;}
		}

	    //字体模式
		new public FontStyle Style
		{
			get{return m_Style;}
			set{m_Style = value;}
		}

	    //无参构造函数
	    public CText(){
	        Init();
	    }

	    //构造函数,用已知的字符串进行构造
	    public CText(string str, PointF aPos){
	        Init();
	        m_Content = str;
	        m_Pos = aPos;
	    }

	    //构造函数
	    public CText(string str, Font f,float size, 
	                   PointF aPos, float ang, 
	                   Color c, FontStyle sty){
	        m_Content = str;
	        m_Font = f;
	        m_Size = size;
	        m_Pos = aPos;
	        m_Angle = ang;
	        m_Color = c;
	        m_Style = sty;
	    }

	    //构造函数,用已知的文本进行构造
		public CText(CText text)
		{
			m_Content =text.Content;
			m_Font =text.Font;
			m_Pos =text.Pos;
			m_Size =text.Size;
			m_Angle =text.Angle;
			m_Color =text.Color;
			m_Style =text.Style;
		}

	    //初始化文本
		private new void Init()
		{
			m_Content = " ";
			m_Size = 20;
			m_Font = new Font("宋体", m_Size, m_Style, GraphicsUnit.Pixel);
			m_Pos = new PointF(0, 0);
			m_Angle = 0;
			m_Color = Color.Black;
			m_Style=FontStyle.Regular;
		}

	    //绘文本
	    override public void Draw(Graphics g,DrawMode aDrawMode)
		{
			switch(aDrawMode){
	            case DrawMode.Normal:
	                m_Color = Color.Black;
					break;
	            case DrawMode.Selec:
	                m_Color = Color.Red;
					break;
	            case DrawMode.Delete:
	                m_Color = Color.White;
					break;
			}
	        PointF Pos= m.WorldtoPage(m_Pos);
			StringFormat sf=new StringFormat(StringFormatFlags.NoWrap);
			g.DrawString(m_Content, m_Font, new SolidBrush(m_Color), Pos.X, Pos.Y, sf);
		}

	    //计算文本的包围矩形
	    override public CBox GetBox()
		{
	        CBox aBox=new CBox();
	        GraphicsPath gp=new GraphicsPath();
			FontFamily fm=new FontFamily("宋体");
			StringFormat sf=new StringFormat(StringFormatFlags.NoWrap);
			int i=2;
			switch (m_Style)
			{
				case FontStyle.Bold:
					i=0;
					break;
				case FontStyle.Italic:
					i=1;
					break;
				case FontStyle.Regular :
					i=2;
					break;
				case FontStyle.Strikeout :
					i=3;
					break;
				case FontStyle.Underline :
					i=4;
					break;
			}
			gp.AddString(m_Content, fm, i, m_Size, m_Pos, sf);
	        RectangleF rect= new RectangleF(0,0,0,0);
			rect=gp.GetBounds();
	        aBox.minX = rect.Left;
	        aBox.minY = rect.Top - rect.Height;
	        aBox.maxX = rect.Right;
	        aBox.maxY = rect.Bottom - rect.Height;
	        gp.Dispose();
	        return aBox;
	    }

	    //拾取文本
		override public bool Pick(PointF aPos)
		{
			if (m.InBox(GetBox(), aPos))
			{
				return true;
			}
			else
			{
				return false;
			}
		}
	}
}

⌨️ 快捷键说明

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