xwjljh 发表于 2009-6-28 23:31:00

如何将CAD窗口显示在VB.NET窗体下呀?

<p>看到<a href="http://www.objectarx.net/bbs/viewthread.php?tid=1754">http://www.objectarx.net/bbs/viewthread.php?tid=1754</a><a href="http://www.objectarx.net/bbs/index.php"></a>论坛发布的CAD窗体显示在C#窗体下,</p><p>如何将其显示在VB.NET下呀?</p><p>网上有关于CAD窗体显示在VB窗体下的代码,但是在VB.NET中无法正常显示,</p><p>望高手给予帮助,谢谢!</p>

雪山飞狐_lzh 发表于 2009-6-29 12:54:00

<p>using System;<br/>using System.Collections.Generic;<br/>using System.ComponentModel;<br/>using System.Data;<br/>using System.Drawing;<br/>using System.Linq;<br/>using System.Text;<br/>using System.Windows.Forms;</p><p>using System.Runtime.InteropServices;</p><p>using Autodesk.AutoCAD.Interop;</p><p>namespace WindowsFormsApplication1<br/>{<br/>&nbsp;&nbsp;&nbsp; </p><p>&nbsp;&nbsp;&nbsp; </p><p>&nbsp;&nbsp;&nbsp; public partial class Form1 : Form<br/>&nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; AcadApplication app;</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public Form1()<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InitializeComponent();<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</p><p><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; static extern IntPtr SetParent(IntPtr child, IntPtr newParent);</p><p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; public static extern IntPtr GetParent(IntPtr hWnd);</p><p><br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; private void Form1_Load(object sender, EventArgs e)<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; app = (AcadApplication)Marshal.GetActiveObject("AutoCad.Application");<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; SetParent(new IntPtr(app.HWND), this.Handle);<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br/>&nbsp;&nbsp;&nbsp; }<br/>}</p>

xwjljh 发表于 2009-6-29 13:51:00

<p>这是C#的,</p><p>有没有VB.NET的呀??</p><p>谢谢了</p>

雪山飞狐_lzh 发表于 2009-6-29 14:26:00

Imports System
Imports System.Runtime.InteropServices
Imports Autodesk.AutoCAD.Interop
Public Class Form1
    Dim app As AcadApplication
    <DllImport("user32.dll")> _
    Friend Shared Function SetParent(ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer
    End Function
    <DllImport("user32.dll")> _
    Friend Shared Function GetParent(ByVal hWnd As Integer) As Integer
    End Function
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
      app = CreateObject("AutoCad.Application.17.1")
      SetParent(New IntPtr(app.HWND), Me.Handle)
      app.Visible = True
    End Sub
    Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
      SetParent(New IntPtr(app.HWND), IntPtr.Zero)
    End Sub
End Class

xwjljh 发表于 2009-6-29 17:51:00

<p>哈哈,谢谢LZH741206老兄</p><p>另,怎么联系您呀?</p><p>希望能够跟您合作,进行技术指导,有报酬的。哈哈</p><p>谢谢了</p><p>我的QQ:75003956</p><p>MSN:xwjljh@hotmail.com</p>

zhangzhenxin197 发表于 2011-7-16 19:22:48

本帖最后由 zhangzhenxin197 于 2011-7-16 19:25 编辑

复制了版主的代码到vb.net里,
第三行有错误,说   “ 未定义类型AcadApplication”
第五行Imports Autodesk.AutoCAD.Interop也显示错误。

请教怎么解决啊?
我用的是cad2007.   vb.net2008   。
是不是要引用什么啊?

急切盼望版主和各位高人的解答,
万分感谢!

哭泣殺豬 发表于 2011-7-17 12:27:51

zhangzhenxin197 发表于 2011-7-16 19:22 static/image/common/back.gif
复制了版主的代码到vb.net里,
第三行有错误,说   “ 未定义类型AcadApplication”
第五行Imports A ...

好像是要引用acax17enu
在C:\Program Files\Common Files\Autodesk Shared
資料夾下

zhangzhenxin197 发表于 2011-7-17 12:31:20

引用 AutoCAD 2007 Type Library 之后,
上面2个问题解决了,
但是又出现“无法创建 ActiveX 组件”错误
如何解决?急盼大侠帮忙解答

zhangzhenxin197 发表于 2011-7-17 12:36:25

刚才又试了下,把第13行   app = CreateObject("AutoCad.Application.17.1")
改成   app = CreateObject("AutoCad.Application.17")
就解决了。把解决的过程也贴上来,希望和我一样的初学者少走弯路。
哎,我们这些菜鸟,一个小小的问题自己要摸索好几天。
希望高手来指导下啊。

zhangzhenxin197 发表于 2011-7-17 12:40:14

然后,又如何让cad窗体在vb.net窗体下缩放呢?以及如何把cad放进vb窗体中的容器中呢?
页: [1] 2
查看完整版本: 如何将CAD窗口显示在VB.NET窗体下呀?