设置控件开发环境
-
回答:
注册控件,运行控件安装目录下的bin\vc100\RegistMxDrawX.exe向系统注册控件
新建一个VB工程
在工具箱窗口上右键弹出菜单上,运行“选择项”命令
在组件窗口中选择MxDrawX控件,点确定就导入控件
点击“视图”=》“对象浏览器”命令,通过VB的对象浏览可以看到控件的所有接口定义:如下
增加控件到对话框上
在对话框上增加一个“绘直线按钮”
在绘直线按钮点击命令中,执行一个控件命令:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
AxMxDrawX1.DoCommand(1)
End Sub
DoCommand函数功能是,执行控件命令,因为控件很多函数,特是与用户交互的函数都必须在控件命令中执行,所以这里调用DoCommand执行控件命令。
这里传的参数“1”是命令的ID号,这个ID号可以随便取值,有多个命令时,ID值不一样就行。
增加控件命令执行事件处理函数:
在命令执行函数中增加交互绘直线代码:
Private Sub AxMxDrawX1_ImplementCommandEvent(ByVal sender As System.Object, ByVal e As AxMxDrawXLib._DMxDrawXEvents_ImplementCommandEventEvent) Handles AxMxDrawX1.ImplementCommandEvent
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(, 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
End If
End Sub
运行效果如图