Вопрос

I am launching a WPF window from AutoCad using

Autodesk.AutoCAD.ApplicationServices.Application.ShowModalWindow(myWindow);

I want this dialog to always appear on the left when opening. I have tried setting myWindow.Left to the x coordinate of the main autocad window and to 0 but it always appears at it's last location. The position can be set when using Window.Show() in WPF but the AutoCAD APIs ShowModalWindow method is necessary in order that the window is always on top of autocad but not any other programs and that it can be minimized with AutoCAD.

Это было полезно?

Решение

Okay I've tested in on my machine, So I know it works. But you may have to tinker a bit to get the right coordinates for your window. In the instance below I used ShowModalDialog. But ShowModalWindow should work similiarly.

Step 1: Change the Form Property >> Start Position: Manual

Step 2: Use a different overloaded method: (Meaning, Change the persistSizeAndPosition to False, this is the whole trick)

Dim LineForm As New frmLineDsgn
LineForm.Left = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Left + 5
LineForm.Top = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Top + 5

Application.ShowModalDialog(LineForm.Handle,LineForm,False)

Looks like this has been asked before on the AutoCAD Forum: Tony Tanzillo has a good answer (and deserves the credit): http://forums.autodesk.com/t5/NET/ShowModalDialog-question/td-p/1744220

You'll want to use a different overloaded method:

Public Shared Function ShowModalWindow(ByVal owner As System.Windows.Window, 
ByVal formToShow As System.Windows.Window, 
ByVal persistSizeAndPosition As Boolean) As Boolean?
 Member of Autodesk.AutoCAD.ApplicationServices.Application

Public Shared Function ShowModalDialog(ByVal owner As System.Windows.Forms.IWin32Window, 
ByVal formToShow As System.Windows.Forms.Form, 
ByVal persistSizeAndPosition As Boolean) As System.Windows.Forms.DialogResult
 Member of Autodesk.AutoCAD.ApplicationServices.Application
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top