Hi,
How do I position a form in the center of the AutoCAD application?
Often users have two monitor screens and the form loads in the primrary screen instead of the one they are using.
Solved! Go to Solution.
Solved by norman.yuan. Go to Solution.
Solved by fieldguy. Go to Solution.
It depends. What type of form is it? Do you need user input other than Yes / No?
http://msdn.microsoft.com/en-CA/library/aa984358(v=vs.71).aspx
http://msdn.microsoft.com/en-us/library/aa984420(v=vs.71).aspx
A modal form but the problem is that I would like to show the form on the monitor that AutoCAD appears on.
ShowModalDialog and ShowModelessDialog both show the form on the primary screen. and not the screen that AutoCAD appears on.
Try the windows form showdialog like this.
myform.StartPosition = FormStartPosition.CenterParent;
myform.ShowDialog();
Dialog box in AutoCAD should be shown using Application.ShowModal[Modeless]Dialog(), rather than Windows.Forms.Form.Show()/ShowDialog().
Application.ShowModal[Modeless]Dialog() has 3 overrides, unless you use the one that has a third boolean argument being false, AutoCAD will remember the dialog box's position when it closes, and show at the same position next time the dialog box is called up.
If you need to write code to position the dialog box, you can have code in Form's Shown event handler to set form's position regardless if AutoCAD remember the form previous position or not.
You can use Widows.Forms.Screen class to iterate through all screens and find primary screen. You can also use Application.MainWindow to find out main AutoCAD window's size/location. With all this information in hand, you can then place your dialog box at the position you want.
Norman Yuan
Can't find what you're looking for? Ask the community or share your knowledge.