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
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
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
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