Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Winform focus after user selection

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
dante.van.wettum
2726 Views, 4 Replies

Winform focus after user selection

Within my addin, i am presenting a winform to the user by using Myform.Show();  (i am not using .ShowDialog() here)

 

On the form there is a button that enables the user to make a selection where i am using this code:

 

            UIDocument uidoc = m_commandData.Application.ActiveUIDocument;
            Document doc = uidoc.Document;

            this.Hide(); //hides the WinForm
            try
            {
                IList<Element> eleRefs = uidoc.Selection.PickElementsByRectangle("Select by rectangle");
                foreach (Element el in eleRefs)
                {
                    //Do something
                }
            }
            catch (Exception ex)
            {
                TaskDialog.Show("Canceled", ex.Message);
            }
            uidoc.RefreshActiveView();
            this.Show(); //show the winform again
            this.BringToFront(); //thy to get the winform on top

 

If i would use the .ShowDialog() instead the of .Show() the revit application would still be frozen and the user is unable to make a selection.

But here is the issue i am facing now:

Once the user finished his selection the Revit application keep beeing the dominant factor and i am unable to get the form to be shown on top of revit again.

Even when i try to cast the this.BringToFront(); on my winform, it Revit that is the front application now.

 

How should i handle this in a fashionable way?

Should i handle the winform in a different way ?

 

 

Edit:
I was thinking i could use this.TopMost = true; to fix this, and it does work, but then i am looking into a way to freeze the Revit GUI in the background (is that possible to do?) so the user cant use revit while the form is still showing (as if it was ShowDialog)

4 REPLIES 4
Message 2 of 5

Dear Dante,

 

Thank you for your query.

 

Have you set up the Revit main window to be the owner of your window?

 

http://thebuildingcoder.typepad.com/blog/2009/02/revit-window-handle-and-modeless-dialogues.html

 

Here is a more recent example using that:

 

http://thebuildingcoder.typepad.com/blog/2014/03/using-generic-collections-with-filters-and-forms.ht...

 

I mostly only use it with ShowForm, but it might help for Show as well in a case like yours.

 

I hope this helps.

 

Best regards,

 

Jeremy



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

Message 3 of 5

its defensively a push in the right direction, as the window gets back on top of the revit application now, but the main issue is not resolved yet:

 

When i use the Form.Show(revit_window); The form will proper display and i can use the button on the form to let the user make a cross selection and send him back to the form when he is done with his selection, while temporarily hiding the form during the selection process.

But in the background, the revit application is not in a frozen state, so you can just push your form to the back or an other monitor and work in your model.

 

When i use the Form.ShowDialog(revit_window); The form will proper display and i can use the button on the form to let the user make a cross selection. But because i only temporarily hide the form instead of closing it, the user is unable to actually make a selection because revit is in a frozen state (waiting for dialog result).

 

So far i only see 1 workaround:

use Form.ShowDialog(revit_window); --->  close() the form on user selection ---> create a new form instance and use the current selection that was made by the user as input.

 

for the end user he wont notice the difference if the form was just temp hidden or he gets prompted an new instance, though it feels as a workaround to create new form instances. So i actually feel like the Form.Show(revit_window);  would be the more cleaner solution, though in that case i would need to find a way to set Revit in a frozen/unfrozen state (as would with showDialog) by the c# code.

Message 4 of 5

For reference:

 

In the end i went with the ShowDialog and just close the form on selection.

Though close event arguments i can distinguish a real close of a close for selection.

depending on that, i start a new form and fetch the selection that was made.

 

Some interesting reading information for anyone that want to dive deeper into this:

Microsoft publishes the source code for the ShowDialog function. Theoretically it would be possible to emulate that freeze behavior yourself.

http://referencesource.microsoft.com/#System.Windows.Forms/winforms/Managed/System/WinForms/Form.cs,...

Message 5 of 5
tf
Contributor
in reply to: dante.van.wettum

Hi,

I see your post is old but I hoping you are still active.   I am trying to do what you accomplished.  That is - use showdialog,  form.close() to allow user input, and once user input is complete showdialog() again.  My issue is when I use form.close() or form.dispose() it still doesn't allow use input. 

Any help will be greatly appreciated.

Thanks in advance

-Ted 

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

Post to forums  

Rail Community


Autodesk Design & Make Report