.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

24 REPLIES 24
Reply
Message 1 of 25
Anonymous
1793 Views, 24 Replies

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


I've noticed strange behaviour when hiding a
modal Form:

 

Dim Form
color=#0000ff size=2>As

size=2>New
MyForm

Application.ShowModalDialog(Form)

Form.Hide

''' Do something...

Form Show

 

When Form.Hide gets executed AutoCAD's
main window completely looses it's

face=Verdana> focus, causing ugly flickering (if only). Is there any smart
workaround to force AutoCAD not to lose focus when Form.Hide gets
executed?

 

Regards,

Maksim Sestic

 

 

 

 
24 REPLIES 24
Message 21 of 25
Irvin
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

Message 22 of 25
matus.brlit
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

Message 23 of 25
SRSDS
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

Message 24 of 25
matus.brlit
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

Message 25 of 25
SRSDS
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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost