Show modeless WinForms/WPF dialogs centerd on Revit's window

christostsar
Contributor

Show modeless WinForms/WPF dialogs centerd on Revit's window

christostsar
Contributor
Contributor

Is it possible to show a modeless WinForms or WPF dialog cented on Revit's window?

How would the window position and width/height be retrieved for this to be possible?

0 Likes
Reply
Accepted solutions (1)
225 Views
1 Reply
Reply (1)

RPTHOMAS108
Mentor
Mentor
Accepted solution

Yes but you have to set the parent/owner

 

For WPF use

Dim Win As New Window()
Dim WHlp1 As New Interop.WindowInteropHelper(Win)
WHlp1.Owner = commandData.Application.MainWindowHandle

RPTHOMAS108_0-1691021829084.png

 

For Forms use

    Public Class RevitWindow
        Implements IWin32Window

        Public ReadOnly Property Handle As IntPtr Implements IWin32Window.Handle
        Public Sub New(UIApp As UIApplication)
            Handle = UIApp.MainWindowHandle
        End Sub
    End Class
    Private Function Obj_XXa(ByVal commandData As Autodesk.Revit.UI.ExternalCommandData,
ByRef message As String, ByVal elements As Autodesk.Revit.DB.ElementSet) As Result

        Dim RW As New RevitWindow(commandData.Application)
        Dim Form1 As New Windows.Forms.Form
        Form1.ShowDialog(RW)

        Return Result.Succeeded

    End Function

RPTHOMAS108_1-1691022597520.png