c# cad 二次开发 类库 对话框 将frame界面添加到类库中

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace _19对话框示例
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e){this.DrawEentity();}//画图形的函数private void DrawEentity(){int width = picBxDrawMap.Width;int height = picBxDrawMap.Height;Bitmap bitmap = new Bitmap(width, height);//创建一个位图对象Graphics graph = Graphics.FromImage(bitmap); //通过位图创建GDI+对象Rectangle rect = new Rectangle((int)(width * 0.15), (int)(height * 0.15), (int)(width * 0.8), (int)(height * 0.8));//绘制图形Rectangle rectExtends = this.DrawLineAndArc(bitmap, graph,rect);//画注释this.DrawDimension(bitmap, graph, rectExtends); //graph.DrawRectangle(new Pen(Brushes.Red), rect);picBxDrawMap.Image = bitmap;}private Rectangle DrawLineAndArc(Bitmap bitmap, Graphics graph, Rectangle rect){double ratio = rect.Width * 1.0 / rect.Height;double width = (double)numUDlength.Value;//矩形宽度double height = (double)numUDheight.Value;//矩形的高度Pen pen = new Pen(Brushes.Black);Point topLineLeftPoint;Point topLineRightPoint;Point rightLineTopPoint;Point rightLineBottomPoint;Point bottomLineLeftPoint;Point bottomLineRightPoint;Point leftLineTopPoint;Point leftLineBottomPoint;if (width/height >= ratio){//以长度占满绘图区域,按比例绘制高度,圆弧// width => rect.Width height = height * rect.Width/wdithheight = height* rect.Width/width;int divHeight = (int)(rect.Height - height)/2;topLineLeftPoint = new Point(rect.X, rect.Y + divHeight);topLineRightPoint = new Point(rect.X+rect.Width, rect.Y + divHeight);rightLineTopPoint = topLineRightPoint;rightLineBottomPoint = new Point(rect.X + rect.Width, rect.Y + rect.Height- divHeight);bottomLineLeftPoint = new Point(rect.X, rect.Y + rect.Height - divHeight);bottomLineRightPoint = rightLineBottomPoint;leftLineTopPoint = topLineLeftPoint;leftLineBottomPoint = bottomLineLeftPoint;}else{//以高度占满绘图区域,按比例绘制长度,圆弧width = width * rect.Height / height;int divWidth = (int)(rect.Width - width) / 2;topLineLeftPoint = new Point(rect.X + divWidth, rect.Y);topLineRightPoint = new Point(rect.X + rect.Width - divWidth, rect.Y);rightLineTopPoint = topLineRightPoint;rightLineBottomPoint = new Point(rect.X + rect.Width - divWidth, rect.Y + rect.Height);bottomLineLeftPoint = new Point(rect.X + divWidth, rect.Y + rect.Height);bottomLineRightPoint = rightLineBottomPoint;leftLineTopPoint = topLineLeftPoint;leftLineBottomPoint = bottomLineLeftPoint;}//绘制上边线graph.DrawLine(pen, topLineLeftPoint, topLineRightPoint);//绘制下边线graph.DrawLine(pen, bottomLineLeftPoint, bottomLineRightPoint);//绘制左边线graph.DrawLine(pen, leftLineTopPoint, leftLineBottomPoint);//绘制右边线graph.DrawLine(pen, rightLineTopPoint, rightLineBottomPoint);Rectangle rectExtends = new Rectangle(topLineLeftPoint.X,topLineLeftPoint.Y,topLineRightPoint.X-topLineLeftPoint.X,leftLineBottomPoint.Y-leftLineTopPoint.Y);return rectExtends;}/// <summary>/// 绘制注释/// </summary>/// <param name="bitmap"></param>/// <param name="graph"></param>/// <param name="rect"></param>private void DrawDimension(Bitmap bitmap,Graphics graph,Rectangle rect){int width = picBxDrawMap.Width;int height = picBxDrawMap.Height;Pen pen = new Pen(Brushes.LawnGreen);string strW = numUDlength.Value.ToString();//水平方向的注释文字string strH = numUDheight.Value.ToString();//垂直方向的注释文字//半径的注释文字#region //水平长度的注释线//Point pointHL1 = new Point(rect.X,(int)(height * 0.05));//Point pointHL2 = new Point(rect.X,(int)(height * 0.14));Point pointHL1 = new Point(rect.X, (int)(height * 0.05));Point pointHL2 = new Point(rect.X,rect.Y-4);Point pointHR1 = new Point(rect.X+rect.Width, (int)(height * 0.05));Point pointHR2 = new Point(rect.X + rect.Width, rect.Y - 4);Point PointHH1 = new Point(rect.X, (int)(height * 0.08));Point PointHH11 = new Point(rect.X + rect.Width / 2 - 12 * (strW.Length / 2)-6, (int)(height * 0.08));Point PointHH2 = new Point(rect.X + rect.Width / 2 + 12 * (strW.Length / 2)+8, (int)(height * 0.08));Point PointHH21 = new Point(rect.X + rect.Width, (int)(height * 0.08));graph.DrawString(strW, new Font("宋体", 12), Brushes.LawnGreen, rect.X + rect.Width / 2-12*(strW.Length/2), (int)(height * 0.08)-8);graph.DrawLine(pen, pointHL1, pointHL2);//水平标注的左侧综线graph.DrawLine(pen, pointHR1, pointHR2);//水平标注的左右侧综线graph.DrawLine(pen, PointHH1, PointHH11);//第一段水平线graph.DrawLine(pen, PointHH2, PointHH21);//第二段水平线//左侧箭头graph.DrawLine(pen, PointHH1, new Point(PointHH1.X + 12, PointHH1.Y - 3));graph.DrawLine(pen, PointHH1, new Point(PointHH1.X + 12, PointHH1.Y + 3));//右侧箭头graph.DrawLine(pen, PointHH21, new Point(PointHH21.X - 12, PointHH1.Y - 3));graph.DrawLine(pen, PointHH21, new Point(PointHH21.X - 12, PointHH1.Y + 3));#endregion#region  //垂直高度的注释Point pointVT1 = new Point((int)(width * 0.05), rect.Y);Point pointVT2 = new Point(rect.X-4, rect.Y);graph.DrawLine(pen,pointVT1, pointVT2); //垂直注释上面横线Point pointVB1 = new Point((int)(width * 0.05), rect.Y + rect.Height);Point pointVB2 = new Point(rect.X - 4, rect.Y + rect.Height);graph.DrawLine(pen, pointVB1, pointVB2); //垂直注释下面横线graph.DrawString(strH, new Font("宋体", 12), Brushes.LawnGreen,(int)(width * 0.08)-strH.Length*10/2, rect.Y+ rect.Height / 2 - 8);//垂直方向的注释文字Point pointVV1 = new Point((int)(width * 0.08), rect.Y);Point pointVV11 = new Point((int)(width * 0.08), rect.Y+rect.Height/2-8);Point pointVV2 = new Point((int)(width * 0.08), rect.Y + rect.Height / 2 + 8);Point pointVV21 = new Point((int)(width * 0.08), rect.Y + rect.Height);graph.DrawLine(pen, pointVV1, pointVV11); //垂直注释第一段线graph.DrawLine(pen, pointVV2, pointVV21); //垂直注释第二段线//上面箭头graph.DrawLine(pen, pointVV1, new Point(pointVV1.X - 3, pointVV1.Y + 12));graph.DrawLine(pen, pointVV1, new Point(pointVV1.X + 3, pointVV1.Y + 12));//下面箭头graph.DrawLine(pen, pointVV21, new Point(pointVV21.X - 3, pointVV21.Y - 12));graph.DrawLine(pen, pointVV21, new Point(pointVV21.X + 3, pointVV21.Y - 12));#endregion//半径注释//绘制中心线#regiondouble lengthDiv = (rect.Height + 10) / 39;Point firstPoint = new Point(rect.X + rect.Width / 2, rect.Y - 5);Point endPoint = new Point((int)(rect.X + rect.Width / 2), (int)(firstPoint.Y + 2 * lengthDiv));for (int i = 0; i < 20; i++){graph.DrawLine(new Pen(Brushes.PaleVioletRed), firstPoint, endPoint);firstPoint.Y = endPoint.Y + (int)lengthDiv;endPoint = new Point((int)(rect.X + rect.Width / 2), (int)(firstPoint.Y + 2 * lengthDiv));}lengthDiv = (rect.Width + 10) / 39;firstPoint = new Point((int)(rect.X-5),(int)(rect.Y + rect.Height/2));endPoint = new Point((int)(firstPoint.X + lengthDiv), (int)(rect.Y + rect.Height / 2));for (int i = 0; i < 22; i++){graph.DrawLine(new Pen(Brushes.PaleVioletRed), firstPoint, endPoint);firstPoint.X = endPoint.X + (int)lengthDiv;endPoint = new Point((int)(firstPoint.X + lengthDiv), (int)(rect.Y + rect.Height / 2));}#endregion}private void numUDlength_ValueChanged(object sender, EventArgs e){this.DrawEentity();}private void numUDheight_ValueChanged(object sender, EventArgs e){this.DrawEentity();}
}

}


c# cad 二次开发 类库 对话框 将frame界面添加到类库中相关推荐

  1. CAD二次开发-MFC对话框domal显示错误

    问题:CAD二次开发时添加MFC对话框后显示错误,显示为多重引线样式管理器. 解决:在对话框之前需要使用AfxGetResourceHandle和AfxSetResourceHandle进行模块资源切 ...

  2. cad 二次开发 插入图片_C#之CAD二次开发(2) 直线对象创建及添加

    0. 前言 从本文开始就正式登上开往CAD二次开发幼儿园的大巴车了!你准备好了吗?车门已经焊死! 还有,本系列笔记是默认大家都有C#的基础的了.这个系列笔记是我自己学习CAD二次开发的一些记录,可能存 ...

  3. c# CAD二次开发 类库 创建各种图形、直线、圆、多段线、正方形、点等

    c# CAD二次开发 类库 创建各种图形.直线.圆.多段线.正方形.点等 using Autodesk.AutoCAD.DatabaseServices; using Autodesk.AutoCAD ...

  4. c# cad 二次开发 类库 块的操作

    c# cad 二次开发 类库 块的操作 using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCAD.DatabaseServi ...

  5. c# cad 二次开发 类库 netload 图层操作、创建图层、删除图层、设置当前图层等

    c# cad 二次开发 类库 netload 图层操作.创建图层.删除图层.设置当前图层等 using Autodesk.AutoCAD.ApplicationServices; using Auto ...

  6. c# cad 二次开发 类库 CAD表格的操作,给CAD添加一个表格

    c# cad 二次开发 类库 CAD表格的操作,给CAD添加一个表格 using Autodesk.AutoCAD.ApplicationServices; using Autodesk.AutoCA ...

  7. c#CAD二次开发全套视频目录

    本人非专业编程人员,设计院画图民工一名.自学CAD编程,也写了一些小程序!初期学习lisp编程语言,基本了解CAD各中开发模块,写过一些程序!前段时间自学C#CAD二次开发,遍布网上无教学视频.经过自 ...

  8. C# Cad二次开发新手入门系列教程(一)开发环境搭建

    目录 前言 开发需要做什么准备? 编写自己的第一个程序 前言 本课程主要针对刚接触Cad二次开发或者准备入门Cad二次开发的朋友,笔者是用的C#进行开发,在该系列教程内,笔者会带着大家从最基础的开发到 ...

  9. CAD二次开发(C#)第三节

    前言 这是最后一部分代码,往后若有时间,对其中的代码详细讲解.初心不变,以便日后查看.特别感谢作者孙成波译作<AutoCAD .NET 开发指南 2012 版>.三部分代码里面有些许失误, ...

最新文章

  1. android button背景随心搭配
  2. 说说身边产品的用户体验
  3. 直播预告 | 双边分支网络BBN:攻坚长尾分布的现实世界任务
  4. 文本框输入值文字消失常用的两种方法
  5. springboot+layui从控制器请求至页面时js失效的解决方法
  6. 一个符合SEO优化标准的网站应具备哪些特征?
  7. 肖修鹏:十年磨一剑,成就靠谱职业经理人
  8. 10060 mysql_navicat连接mysql服务端报10060错误解决过程如下
  9. 【转账】API自动化测试
  10. React源码分析 - 组件初次渲染
  11. windows文件自动同步
  12. python教师管理系统,Python面向对象实战:学生教师信息管理(3)
  13. Lonza高通量384孔Nucleofector电转平台
  14. Adversarial Generation of Continuous Images 阅读笔记
  15. android微信图片选择框架,Android仿微信图片选择器ImageSelector使用详解
  16. 网络原理之TCP协议特性
  17. 小米红米手机无电池24H开机完美解决方案
  18. Python题综合练习一
  19. 数据库配置口令复杂度策略和口令有效期策略
  20. 关于PLM/EVT/DVT/PVT/MP的解释

热门文章

  1. 48MW双馈风电机组并网仿真模型 机端由24台2MW双馈风机构成48MW风电场,出口电压690v,经升压变压器及线路阻抗连接至120kv交流电网
  2. 斗兽棋概要设计说明书
  3. 进程控制块(PCB) 包含哪些信息
  4. 【MBD】使用28335测试ePWM
  5. LCD驱动电路IC学习
  6. 阿里笔试 8-28 字符串交换
  7. matlab 画多个函数,Matlab中一个figure函数画多个子图和多个figure函数画多个字图...
  8. 仿微信、短信、QQ等消息数目右上角红色小圆球气泡显示(基于Android XML布局文件实现)
  9. 芒果超媒上半年营收67亿:同比降15% 广告收入降31%
  10. 如何提升自己编写软件需求文档能力