Windows form on same screen as revit

Windows form on same screen as revit

Gilles.Lagrilliere
Advocate Advocate
1,433 Views
8 Replies
Message 1 of 9

Windows form on same screen as revit

Gilles.Lagrilliere
Advocate
Advocate

Hello

 

I made a plugin where a form appears if I click on my plugin button.

I work with a laptop and have two additional monitors.

the form always pop ups on my laptop screen, instead I want it to pop up on the screen where Revit is running.

How can I accomplish this?

 

I hope you guys can help me with this

 

thanks in advance!

0 Likes
Accepted solutions (1)
1,434 Views
8 Replies
Replies (8)
Message 2 of 9

RPTHOMAS108
Mentor
Mentor
Accepted solution

Set the parent as Revit window via it's handle

Form.Show(Owner) or Form.ShowDialog(Owner) 

 

Then set Form.StartPosition to CenterParent.

Message 3 of 9

Omar_Amen
Advocate
Advocate

Hi @RPTHOMAS108 ,
I don't know how can I get the (owner) Arg. from Revit API,
it's seems that it needs IWin32Window object but I don't know how to retrieve it

0 Likes
Message 4 of 9

Gilles.Lagrilliere
Advocate
Advocate

hello

 

check this link out: https://thebuildingcoder.typepad.com/blog/2010/06/revit-parent-window.html

this helped me to get IWin32Window object.

Message 5 of 9

RPTHOMAS108
Mentor
Mentor

Not used forms in a long while but I would probably try this:

 

 Public Function Obj_211130a(commandData As ExternalCommandData, ByRef message As String, elements As ElementSet) As Result

        Dim app = commandData.Application
        Dim uidoc = commandData.Application.ActiveUIDocument
        Dim IntDoc = uidoc.Document

        Dim F As New System.Windows.Forms.Form
        F.StartPosition = WF.FormStartPosition.CenterParent

        F.ShowDialog(New RvtWindow(app))

        Return Result.Succeeded
    End Function
    Public Class RvtWindow
        Implements Interop.IWin32Window

        Private IntHwnd As IntPtr
        Public Sub New(App As UIApplication)
            IntHwnd = App.MainWindowHandle
        End Sub

        Public ReadOnly Property Handle As IntPtr Implements IWin32Window.Handle
            Get
                Return IntHwnd
            End Get
        End Property
    End Class

 

Message 6 of 9

Omar_Amen
Advocate
Advocate

thanks both worked 😊

0 Likes
Message 7 of 9

jeremy_tammik
Alumni
Alumni

Note that the post from 2010 os obsolete and has been superseded by:

  

Two new properties in the Autodesk.Revit.UI namespace provide access to the handle of the Revit main window:

  • UIApplication.MainWindowHandle
  • UIControlledApplication.MainWindowHandle

  

https://thebuildingcoder.typepad.com/blog/2018/11/revit-window-handle-and-parenting-an-add-in-form.h...

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
Message 8 of 9

Gilles.Lagrilliere
Advocate
Advocate

How do I make it work with the new properties?

I tried frm.ShowDialog(CommandData.Application.MainWindowHandle)

but that doesn't work.

 

Thanks in advance!

0 Likes
Message 9 of 9

jeremy_tammik
Alumni
Alumni

You need to convert it to the appropriate data type. An example of how this can be done is provided by the module CmdJumpToRevitPosition.cs in The Building Coder samples:

    

      JtWindowHandle h = new JtWindowHandle( uiapp.MainWindowHandle );

      JumpToPosition jumper = new JumpToPosition( view, h );

 

Look at the description of updating The Building Coder samples to use MainWindowHandle:

 

https://thebuildingcoder.typepad.com/blog/2018/11/revit-window-handle-and-parenting-an-add-in-form.h...

   

Please read the blog post more carefully before asking further questions. I wrote it to avoid having to repeat myself.

  

Jeremy Tammik Developer Advocacy and Support + The Building Coder + Autodesk Developer Network + ADN Open
0 Likes