主要用到函数说明:
_DMxDrawX::DrawLine
绘制一个直线。详细说明如下:
参数 | 说明 |
---|---|
DOUBLE dX1 |
直线的开始点x坐标 |
DOUBLE dY1 |
直线的开始点y坐标 |
DOUBLE dX2 |
直线的结束点x坐标 |
DOUBLE dY2 |
直线的结束点y坐标 |
_DMxDrawX::DrawText
绘制一个单行文字。详细说明如下:
参数 | 说明 |
---|---|
DOUBLE dPosX |
>文字的位置的X坐标 |
DOUBLE dPosY |
文字的位置的Y坐标 |
BSTR pszText |
文字内容字符串 |
DOUBLE dHeight |
文字高度 |
DOUBLE dRotation |
文字的旋转角度 |
SHORT horizontalMode |
文字的水平对齐方式,0=kTextLeft,1=kTextCenter,2=kTextRight |
SHORT verticalMode |
文字的竖直对齐方式,1=kTextBottom,2=kTextVertMid,3=kTextTop |
IMxDrawCustomEntity::Draw
把实体绘制到图上。一般用于动态拖放时,在拖放结束时,绘制到图上。
c#中实现代码说明:
动态拖放时的绘制事件:
private void DynDrawMatrix() { // 创建一个与用户交互取点的对象。 MxDrawPoint point1 = (MxDrawPoint)axMxDrawX1.GetPoint(false, 0, 0, "\n 点取开始点:"); if (point1 == null) { return; } MxDrawUiPrPoint getSecondPt = new MxDrawUiPrPoint(); getSecondPt.message = "第二点"; getSecondPt.basePoint = point1; //调用 MxDrawCustomEntity spDrawData = getSecondPt.InitUserDraw("TestDynDrawMatrix"); // 设置动态绘制参数. spDrawData.SetPoint("BasePoint", point1); // 开始取第二个点。 if (getSecondPt.go() != MCAD_McUiPrStatus.mcOk) return; spDrawData.Draw(); }
动态绘制矩形框:
private void axMxDrawX1_DynWorldDraw(object sender, AxMxDrawXLib._DMxDrawXEvents_DynWorldDrawEvent e) { MxDrawCustomEntity pCustomEntity = (MxDrawCustomEntity)e.pData; MxDrawWorldDraw pWorldDraw = (MxDrawWorldDraw)e.pWorldDraw; string sGuid = pCustomEntity.Guid; MxDrawPoint curPoint = new MxDrawPoint(); curPoint.x = e.dX; curPoint.y = e.dY; if(sGuid == "TestDynDrawMatrix") { //与用户交互在图面上提取一个点 MxDrawPoint vBasePt = pCustomEntity.GetPoint("BasePoint"); //计算中心点位置 MxDrawPoint centerPt = new MxDrawPoint(); { centerPt.x = curPoint.x + (vBasePt.x - curPoint.x) / 2; centerPt.y = curPoint.y + (vBasePt.y - curPoint.y) / 2; } //计算面积(取绝对值) double arec = Math.Abs(vBasePt.x - curPoint.x) * Math.Abs(vBasePt.y - curPoint.y); //计算周长 double girth = 2 * (Math.Abs(vBasePt.x - curPoint.x) + Math.Abs(vBasePt.y - curPoint.y)); //变换视区长度 double dHeigth = axMxDrawX1.ViewLongToDocCoord(15); //绘制一个单行文字 //参数一为文字的位置的X坐标 ;参数二为文字的位置的Y坐标 ;参数三为文字内容字符串 //参数四为文字高度;参数五为文字的旋转角度 //参数六为文字的水平对齐方式,0=kTextLeft,1=kTextCenter,2=kTextRight //参数七文字的竖直对齐方式,1=kTextBottom,2=kTextVertMid,3=kTextTop pWorldDraw.DrawText(centerPt.x, centerPt.y, "面积:" + arec, dHeigth, 0, MCAD_McHorizontalAlignment.mcHorizontalAlignmentCenter, MCAD_McVerticalAlignment.mcVerticalAlignmentBottom); pWorldDraw.DrawText(centerPt.x, centerPt.y, "周长:" + girth, dHeigth, 0, MCAD_McHorizontalAlignment.mcHorizontalAlignmentCenter, MCAD_McVerticalAlignment.mcVerticalAlignmentTop); //绘制一个直线 //参数一直线的开始点x坐标,参数二直线的开始点y坐标,参数三直线的结束点x坐标,参数四直线的结束点y坐标 pWorldDraw.DrawLine(vBasePt.x, vBasePt.y, vBasePt.x, curPoint.y); pWorldDraw.DrawLine(vBasePt.x, curPoint.y, curPoint.x, curPoint.y); pWorldDraw.DrawLine(curPoint.x, curPoint.y, curPoint.x, vBasePt.y); pWorldDraw.DrawLine(curPoint.x, vBasePt.y, vBasePt.x, vBasePt.y); } }
来源:https://www.cnblogs.com/yzy0224/p/11064821.html