www.mxdraw.com
内容索引主面
前一个向上下一个
_DMxDrawXEvents::MouseEvent 方法

控件中的鼠标事件

IDL
[id(3),helpstring("MouseEvent")]
void MouseEvent(LONG lType, DOUBLE dX, DOUBLE dY, LONG* lRet);
参数 
说明 
LONG lType 
事件类型,1鼠标移动,2是鼠标左键按下,3是鼠标右键按下,4是鼠标左键双击 5是鼠标左键释放 6是鼠标右键释放 7是鼠标中键按下 8是鼠标中键释放 9是鼠标中键双击 10是鼠标中键滚动 
DOUBLE dX 
事件发生时的鼠标X坐标,文档坐标 
DOUBLE dY 
事件发生时的鼠标Y坐标,文档坐标 
LONG* lRet 
lRet 返回非0,消息将不在往下传递 

例如: 提示鼠标双击下被点击的实体C#代码

     private void axMxDrawX1_MouseEvent(object sender, AxMxDrawXLib._DMxDrawXEvents_MouseEventEvent e)
    {
    if(e.lType == 4)
    {
        // 鼠标左键双击.
        // 构建选择集,找到鼠标左建双击下的实体。

        MxDrawSelectionSet ss = new MxDrawSelectionSet();
        MxDrawResbuf filter = new MxDrawResbuf();
        //filter.AddString("LINE",5020);
        MxDrawPoint point = new MxDrawPoint();
        point.x = e.dX;
        point.y = e.dY;
        ss.SelectAtPoint2(point,filter);
        if(ss.Count > 0)
        {
            MxDrawEntity ent = ss.Item(0);
            MessageBox.Show("点击了" + ent.ObjectName + "对象");
            /*
            if (ent is MxDrawLine)
            {
                MxDrawLine line = (MxDrawLine)ent;
            }
             */
        }
        e.lRet = 1;
        // 取消后面的命令。
        axMxDrawX1.SendStringToExecute("");
    }
    else if(e.lType == 10)
    {
        // 鼠标中键滚动
        MxDrawResbuf spVarValue
                 = (MxDrawResbuf)axMxDrawX1.Call("GetMouseWheelDelta", "");
        // lDelta是滚轮滚动的数目
        Int32 lDelta = spVarValue.AtLong(1);
        if(lDelta > 0)
        {
            MessageBox.Show("Zoom 放大");
        }
        else
        {
            MessageBox.Show("Zoom 缩小");
        }
        
    }
}

例如: Js代码

function MouseEvent(dX,dY,lType)
{

    if(lType == 4)
    {
              
        var axMxDrawX1 = document.getElementById("MxDrawXCtrl");
        var ss = axMxDrawX1.Call("Mx_NewSelectionSet","");
        var pt = axMxDrawX1.Call("Mx_NewPoint","");
                var fil = axMxDrawX1.Call("Mx_NewResbuf","");
        pt.x = dX;
                pt.y = dY;
               
                ss.SelectAtPoint2(pt,fil);
        
            if(ss.Count > 0)
                {
                    var ent = ss.Item(0);
                    alert("点击了" + ent.ObjectName + "对象");
                }
        // 取消后面的命令。
            axMxDrawX1.SendStringToExecute("");
        return 1;
       
        }
    
      
    return 0;
}

例如: JS,响应鼠标点击图片对象.

                var draw = document.getElementById("MxDrawXCtrl");
                draw.ImplementMouseEventFun = function MouseEvent(dX, dY, lType) { 
                    if(lType == 2)
                    {
    
                        // 鼠标左键按下
        
                        // dTol是搜索范围,50是屏幕像素.
                        var dTol = 50;
        
                        // 临时修改CursorWidth的大小,用FindEntAtPoint函数确定搜索范围.
                        var bak = draw.CursorWidth;
                        draw.CursorWidth = dTol;
        
                        // 搜索过滤条件,只选择图片.
                        var filter = draw.NewResbuf();
        
                        // MxImageMark是图片对象的DXF组码名称,5020在DXF组码,代表MxImageMark是对象类型.
                        filter.AddStringEx("MxImageMark",5020);
        
                        // 查找鼠标点击的实体。
                        var ent = draw.FindEntAtPoint(dX,dY,filter);
        
                        // 恢复光标拾取框的大小.
                        draw.CursorWidth = bak;
                        if(ent != null)
                        {
        
                            alert("点击了一个图片");
                            // 设置1,表示鼠标事件,不再往下传递.
                            mxOcx.SetEventRet(1);
                        }
        
                        //
        
        
                    };
                };

例如: C#

        private void axMxDrawX1_MouseEvent(object sender, AxMxDrawXLib._DMxDrawXEvents_MouseEventEvent e)
            {
                if (e.lType == 2)
                {
                    // 设置1,表示鼠标事件,不再往下传递.
                    e.lRet = 1;

                    // 取消后面的命令。
                    axMxDrawX1.SendStringToExecute(" ");

                    // 鼠标左键按下
                    MxDrawResbuf param = new MxDrawResbuf();
                    MxDrawPoint pt = new MxDrawPoint();
                    pt.x = e.dX;
                    pt.y = e.dY;

                    param.AddPoint(pt);

                    MxDrawResbuf ret = (MxDrawResbuf)axMxDrawX1.CallEx("ExApp_FindRegion", param);

                    if (ret.AtString(0) != "Ok")
                        return;

                    // 找到了区域。

                    MxDrawPolyline pl = new MxDrawPolyline();
                    for (Int32 i = 1; i < ret.Count; i++)
                    {
                        MxDrawPoint tmpPt = ret.AtPoint(i);
                        if (i == 1)
                        {
                            axMxDrawX1.PathMoveTo(tmpPt.x, tmpPt.y);
                        }
                        else
                        {
                            axMxDrawX1.PathLineTo(tmpPt.x, tmpPt.y);
                        }
                        pl.AddVertexAt(tmpPt);
                    }

                    // 把点中的区域进行绘制。 
                    axMxDrawX1.DrawCADColor = 255;
                    axMxDrawX1.DrawPathToHatch(1.0);

                    // 计算面积.
                    axMxDrawX1.UpdateDisplay();
                    double dArea = 0.0;
                    if (pl.GetArea(out dArea))
                    {
                        MessageBox.Show(dArea.ToString());
                    }

         
        
                }
    
            }
Copyright (c) 2010. All rights reserved.
你认为该帮助怎么样? 发送反馈信息!