【转帖】在文档窗口中添加控件的简单原型



http://bbs.mjtd.com/thread-79240-1-1.html


        <DllImport("user32.dll")> _
        Private Shared Function SetParent(ByVal child As IntPtr, ByVal newParent As IntPtr) As IntPtr
        End Function


        Shared button1 As New System.Windows.Forms.Button()
        <CommandMethod("sab")> _
        Public Shared Sub ShowMe()
            If button1 Is Nothing Then
                button1 = New System.Windows.Forms.Button()
            End If
            button1.Location = New System.Drawing.Point(31, 29)
            button1.Name = "button1"
            button1.Size = New System.Drawing.Size(87, 35)
            button1.TabIndex = 0
            button1.Text = "button1"
            button1.UseVisualStyleBackColor = True
            AddHandler button1.Click, AddressOf button1_Click
            Dim doc As Autodesk.AutoCAD.ApplicationServices.Document = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument

            SetParent(button1.Handle, doc.Window.Handle)
        End Sub


        Private Shared Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
            button1.Dispose()
        End Sub



Public Class Class1
    <DllImport("user32.dll")> _
    Shared Function SetParent(child As IntPtr, newParent As IntPtr) As IntPtr
    End Function

    Shared panSysMenu As UcSysMenu
    <Autodesk.AutoCAD.Runtime.CommandMethod("MyMenu")> _
    Public Sub loadSysMenu()
        Dim DocCollection As DocumentCollection = Application.DocumentManager
        '文档创建事件
        AddHandler DocCollection.DocumentCreated, AddressOf DocCollection_DocumentCreated 
        For Each doc As Document In DocCollection
            panSysMenu = New UcSysMenu()
            panSysMenu.Location = New System.Drawing.Point(31, 29)
            SetParent(panSysMenu.Handle, doc.Window.Handle)
        Next
    End Sub


    Sub DocCollection_DocumentCreated(sender As Object, e As DocumentCollectionEventArgs)
        panSysMenu = New UcSysMenu()
        panSysMenu.Location = New System.Drawing.Point(31, 29)
        SetParent(panSysMenu.Handle, Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Window.Handle)
    End Sub
End Class




Dismiss Dialogue using Windows API

【转帖】获取AutoCAD命令行窗口句柄的函数

欢迎关注微信公众账号ByCAD