Hello,
How to switch focus to AutoCAD document window from my form of C# .NET plug-in.
After user pressed the button, I invite him to input a point, but my form still on top.
And it is nessesary to press minimize button, next to set a Focus on Autocad window, then to pick a point.
It is not handy enough.
I did not find a property to set a focus in class of Application.MainWindow.
How can I do it?
Thank you, in advance.
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Thanks, but I'm using modeless autocad dialog method.
Is there explicit call of any method to change a focus?
Hi,
Assuming the modeless form is launched from an autoCAD command :
[CommandMethod("Test")] public void Test() { Application.ShowModelessDialog(new ModelesssForm()); }
In the ModelessForm class, the button click event handler may be:
private void button1_Click(object sender, EventArgs e) { this.Hide(); // this is not mandatory Document doc = AcAp.DocumentManager.MdiActiveDocument; Editor ed = doc.Editor; using (doc.LockDocument()) // this is needed from a modeless form { // set focus to AutoCAD Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView(); // do your stuff here PromptPointResult ppr = ed.GetPoint("\nPick a point: "); // ... } this.Show(); // this is mandatory if the form have been hidden }
from AutoCAD 2014 onwards it is
Autodesk.AutoCAD.ApplicationServices.Application.MainWindow.Focus();
In the solution from SENL1362 you can replace adsw_acadDocWnd() with:
Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Window.Handle
It can be used in AutoCAD 2010 or even earlier I think.
But the other solutions Utils.SetFocusToDwgView() and MainWindow.Focus() are much more straightforward.
When i do this using Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView(); afterbutton click on modeless form if my form is not over the acad window i go straight into the editor, if my form was even partially over the acad window i have to click in the window once to get into the editor.
Any ideas?
@Anonymous a écrit :
When i do this using Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView(); afterbutton click on modeless form if my form is not over the acad window i go straight into the editor, if my form was even partially over the acad window i have to click in the window once to get into the editor.
Any ideas?
Did you try @CADbloke's suggestion in its upper reply?
Yes, I can see his is for 2014 and later, they both actually produce the same result in 2017.
Its weird if I run the command on the form then move my cursor completely outside of autocad and back again I get the crosshairs. But for the period between the form and the boundary of the acad window it’s just a regular windows cursor.
I also have the mouse_leave function on my form so doubt it’s that.
From Kean Walmsley blog:
"Once again there’s our important rule of thumb when it comes to implementing a modeless UI: rather than manually locking the current document, it’s safer to define a command – which will implicitly lock the current document – and call that from the UI via SendStringToExecute()."
Can't find what you're looking for? Ask the community or share your knowledge.