Author Topic: AutoCAD window minimized to an icon  (Read 2562 times)

0 Members and 1 Guest are viewing this topic.

chobo

  • Newt
  • Posts: 24
AutoCAD window minimized to an icon
« on: May 29, 2012, 04:25:26 AM »
I'm New to VB.NET..
AutoCAD loses focus and whatever other application running at that time becomes the
foreground application.
Run the program ->
ShowModelessDialog to display main Form(frmParent) -> Click [Child] Button ->
ShowModelessDialog to display sub Form(frmChild) -> Click [Get Point] Button ->
Main and Sub Form.Visible = False -> !! AutoCAD window minimized !!
What's Wrong With My Code??

Test.vb
Code: [Select]
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices

Public Class test
    <CommandMethod("XXX")> _
    Public Sub TEST_FORM()
        Dim Form As New frmParent
        Application.ShowModelessDialog(New AcadMainWindow, Form, False)
    End Sub
End Class

Public Class AcadMainWindow
    'By Tony Tanzillo
    'Note that this class implements the IWin32Window interface from System.Windows.Forms,
    'rather than the one from System.Windows:
    Implements System.Windows.Forms.IWin32Window

    Public ReadOnly Property Handle() As IntPtr Implements System.Windows.Forms.IWin32Window.Handle
        Get
            Return Application.MainWindow.Handle
        End Get
    End Property
End Class

frmParent.vb
Code: [Select]
Imports Autodesk.AutoCAD.ApplicationServices

Public Class frmParent
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Form As New frmChild(Me)
        Application.ShowModelessDialog(Me, Form, False)
    End Sub
End Class

frmChild.vb
Code: [Select]

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry

Public Class frmChild
    Private _Parent As Form

    Public Sub New(ByVal Parent As frmParent)
        If Parent Is Nothing Then
            Throw New NullReferenceException("NULL!")
        End If
        _Parent = Parent
        InitializeComponent()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        _Parent.Visible = False
        Me.Visible = False
        Try
            Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
            Dim pPO As New PromptPointOptions(vbCr & "Select Point:")
            Dim pPR As PromptPointResult
            pPR = ed.GetPoint(pPO)
            If pPR.Status = PromptStatus.OK Then
                MsgBox("OK")
            End If
        Catch ex As Exception

        Finally
            _Parent.Visible = True
            Me.Visible = True
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub
End Class

TheMaster

  • Guest
Re: AutoCAD window minimized to an icon
« Reply #1 on: May 31, 2012, 09:57:47 AM »
I'm New to VB.NET..
AutoCAD loses focus and whatever other application running at that time becomes the
foreground application.
Run the program ->
ShowModelessDialog to display main Form(frmParent) -> Click [Child] Button ->
ShowModelessDialog to display sub Form(frmChild) -> Click [Get Point] Button ->
Main and Sub Form.Visible = False -> !! AutoCAD window minimized !!
What's Wrong With My Code??

Test.vb
Code: [Select]
Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices

Public Class test
    <CommandMethod("XXX")> _
    Public Sub TEST_FORM()
        Dim Form As New frmParent
        Application.ShowModelessDialog(New AcadMainWindow, Form, False)
    End Sub
End Class

Public Class AcadMainWindow
    'By Tony Tanzillo
    'Note that this class implements the IWin32Window interface from System.Windows.Forms,
    'rather than the one from System.Windows:
    Implements System.Windows.Forms.IWin32Window

    Public ReadOnly Property Handle() As IntPtr Implements System.Windows.Forms.IWin32Window.Handle
        Get
            Return Application.MainWindow.Handle
        End Get
    End Property
End Class

frmParent.vb
Code: [Select]
Imports Autodesk.AutoCAD.ApplicationServices

Public Class frmParent
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Form As New frmChild(Me)
        Application.ShowModelessDialog(Me, Form, False)
    End Sub
End Class

frmChild.vb
Code: [Select]

Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.EditorInput
Imports Autodesk.AutoCAD.Geometry

Public Class frmChild
    Private _Parent As Form

    Public Sub New(ByVal Parent As frmParent)
        If Parent Is Nothing Then
            Throw New NullReferenceException("NULL!")
        End If
        _Parent = Parent
        InitializeComponent()
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        _Parent.Visible = False
        Me.Visible = False
        Try
            Dim ed As Editor = Application.DocumentManager.MdiActiveDocument.Editor
            Dim pPO As New PromptPointOptions(vbCr & "Select Point:")
            Dim pPR As PromptPointResult
            pPR = ed.GetPoint(pPO)
            If pPR.Status = PromptStatus.OK Then
                MsgBox("OK")
            End If
        Catch ex As Exception

        Finally
            _Parent.Visible = True
            Me.Visible = True
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Me.Close()
    End Sub
End Class

Not sure why this is happening, but you might try calling the Editor.StartUserInteraction() method before you show your child form, and disposing the object it returns after the form is closed. I also would not specify the parent form in the call to ShowModelessDialog(), and instead give it the AutoCAD main window.

chobo

  • Newt
  • Posts: 24
Re: AutoCAD window minimized to an icon
« Reply #2 on: May 31, 2012, 08:45:29 PM »
Not sure why this is happening, but you might try calling the Editor.StartUserInteraction() method before you show your child form, and disposing the object it returns after the form is closed. I also would not specify the parent form in the call to ShowModelessDialog(), and instead give it the AutoCAD main window.

Thank you for the answer.
One thing I have learned thanks to your help
« Last Edit: May 31, 2012, 08:50:11 PM by chobo »

GUIDO ROOMS

  • Guest
Re: AutoCAD window minimized to an icon
« Reply #3 on: June 11, 2012, 03:14:06 PM »
I've been having the same problem.
At the time I was working with XP professional,AutoCAD 2010 and VB Express.
Believe it or not, the day I installed Windows 7 the problem simply vanished.
(still working with AutoCAD 2010, though)

Greetings.