.NET

Reply
Distinguished Contributor
Irvin
Posts: 112
Registered: ‎04-22-2009
Message 21 of 25 (404 Views)

Re: Hiding a Form causes entire ACAD application to lose focus (AutoCAD 2006)

05-19-2011 06:28 AM in reply to: matus.brlit

Hi Matus,

 

Hiding Modal Forms during User Interaction

This is a unique requirement that AutoCAD based developers face very often. The scenario: A modal form is displayed with some information about one’s application. A modal form as many are aware does not allow user interaction with the AutoCAD editor as long as it is displayed. The modal form has to be closed before the control returns to the AutoCAD editor. This however is not always possible; we may want to temporarily access the AutoCAD editor (to say pick a point or select an entity) and return back to our Modal form to continue with our application’s workflow.

 

A developer who has developed a generic .NET application before may be tempted to just “hide” the .NET form and “restore” it when we are done with the AutoCAD editor. This however causes a set of problems subtle enough to escape even the most experienced developers at first glance. For instance, a developer who “hides the form” also has to make sure, the AutoCAD editor is “activated” and the focus is set to it. That means extra code. However this is a very small problem compared to the real issue. Because of the way AutoCAD is architected, one has to be very careful about how AutoCAD switches between UI elements and how code that access AutoCAD resources (like the editor and entities) from a UI element does it. Not doing it right could mean an AutoCAD crash (we have seen that before!) with no clue as to what caused it.

 

The AutoCAD .NET API makes it very simple and easy to implement user interaction without the need to worry about these issues. Specifically, the AutoCAD .NET class “EditorUserInteraction” helps us in wrapping up all the functionality that one needs to perform safe switching between a modal form and the AutoCAD editor. The typical usage of this code would look like this:

 

using (EditorUserInteraction edUsrInt = ed.StartUserInteraction(this))
                    {
                        // Code to add a couple of entities to AutoCAD
                        PromptPointOptions prPtOpts = new PromptPointOptions("\nPlease select a point to place the ellipse:");
                        PromptPointResult prPtRes = ed.GetPoint(prPtOpts);

                        Utilities.AddEllipse(prPtRes.Value);

                        prPtOpts.Message = "\nPlease select a point to place the circle:";
                        prPtRes = ed.GetPoint(prPtOpts);

                        Utilities.AddCircle(prPtRes.Value);

                        ed.WriteMessage("\nAdded an Entity");
                        edUsrInt.End(); // End the UserInteraction.
                        this.Focus();
                    }

 

 The object “ed” represents the AutoCAD editor.

 

I copied this from a class from Autodesk University, here's the link to that class:

 

http://au.autodesk.com/?nd=class&session_id=5055

 

Hope this helps to sovle your problem.

 

Kind regards.

 

Irvin

Mentor
matus.brlit
Posts: 246
Registered: ‎03-11-2008
Message 22 of 25 (400 Views)

Re: Hiding a Form causes entire ACAD application to lose focus (AutoCAD 2006)

05-19-2011 06:48 AM in reply to: Irvin

thanks for trying to help, but this is not what i want to do

I'm not hiding the first form to get some user interaction in autocad, but to open another form and i don't want to have them both displayed, after user does his job on the other form, that one is closed and he gets back to the first form

 

I know about that method, that you mention, but i have no problems using me.hide / me.show for getting user input, it only occurs, when i want to show another form

Distinguished Contributor
SRSDS
Posts: 243
Registered: ‎04-15-2011
Message 23 of 25 (167 Views)

Re: Hiding a Form causes entire ACAD application to lose focus (AutoCAD 2006)

05-11-2013 03:37 PM in reply to: matus.brlit

Old post but I'll reply.

 

I don't know if this is an option but I've found that closing the form doesn't result in the flash

 

me.close

Mentor
matus.brlit
Posts: 246
Registered: ‎03-11-2008
Message 24 of 25 (145 Views)

Re: Hiding a Form causes entire ACAD application to lose focus (AutoCAD 2006)

05-12-2013 10:40 PM in reply to: SRSDS

yeah, that might be, but at some point later, i want to show the first form again, so I'm not closing it, just hiding

Distinguished Contributor
SRSDS
Posts: 243
Registered: ‎04-15-2011
Message 25 of 25 (134 Views)

Re: Hiding a Form causes entire ACAD application to lose focus (AutoCAD 2006)

05-13-2013 02:16 AM in reply to: matus.brlit

I had the same problem. I just reload the form with data from storage variables.

It's probably not that difficult in my case though.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community