以管理员身份启动CAD控件 \Bin\vc100\RegistMxDrawX.exe ,以向系统注册梦想CAD控件。
运行Visual Studio,点击左上角【文件(F)】->【新建(N)】->【项目(P)】,选择 Visual Basic ,使用Windows 窗体应用(.NET Framework)新建一个工程。
    
     
在工具箱窗口单击右键,选择“ 选择项 ”,在弹出的“ 选择工具箱项 ”中点击“ COM组件 ”Tab页。 找到“ MxDrawX52 Control ”并勾选,点击确定添加。
在工具箱中找到 MxDrawX52 Control ,拖放至WinForm窗口,并适当调整大小,编译运行。 效果如下:
    
    
增加交互绘直线功能。
在对话框上增加一个“ 绘制直线 ”按钮,并为它添加单击事件。 在时间内添加如下代码:
AxMxDrawX1.DoCommand(1)
DoCommand 函数的功能是执行控件命令;所有与用户交互的函数必须在控件命令中执行,所以这里调用DoCommand执行控件命令。 这里传的参数“1”是命令ID号,这个ID号可以随意取值,有多个命令时,ID值不能重复。
增加CAD控件命令执行事件处理函数并添加如下代码:
        Dim app As MxDrawXLib.MxDrawApplication
        app = New MxDrawXLib.MxDrawApplication
        '绘制直线命令代码
        If e.iCommandId = 1 Then
            Dim curSpace2 As MxDrawXLib.MxDrawBlockTableRecord
            curSpace2 = app.WorkingDatabase.CurrentSpace
            Dim mxUtility As MxDrawXLib.MxDrawUtility
            mxUtility = New MxDrawXLib.MxDrawUtility
            Dim getPt1 As MxDrawXLib.MxDrawPoint
            getPt1 = mxUtility.GetPoint(getPt1, Chr(13) + Chr(10) + "点取第一点:")
            If (getPt1 Is Nothing) Then
                MsgBox("用户取消..")
                ' 释放非托管对象
                System.Runtime.InteropServices.Marshal.ReleaseComObject(curSpace2)
                curSpace2 = Nothing
                Exit Sub
            End If
            Dim getPt2 As MxDrawXLib.MxDrawPoint
            getPt2 = mxUtility.GetPoint(getPt1, Chr(13) + Chr(10) + "点取第二点:")
            If (getPt2 Is Nothing) Then
                MsgBox("用户取消..")
                ' 释放非托管对象
                System.Runtime.InteropServices.Marshal.ReleaseComObject(curSpace2)
                curSpace2 = Nothing
                Exit Sub
            End If
            Dim newLine As MxDrawXLib.MxDrawLine
            newLine = curSpace2.AddLine(getPt1.x, getPt1.y, getPt2.x, getPt2.y)
            newLine.colorIndex = MxDrawXLib.MCAD_COLOR.mcRed
            ' 释放非托管对象
            System.Runtime.InteropServices.Marshal.ReleaseComObject(curSpace2)
            curSpace2 = Nothing
            System.Runtime.InteropServices.Marshal.ReleaseComObject(newLine)
            newLine = Nothing
    