I need to position a dialog box in the center of the user’s screen, no matter what the screen resolution or size.
.
I’ve tried some of the ideas in these topics…
e
But I haven’t succeeded.
.
========SIMPLE CODE PIECE========
Option Explicit
Option Compatible
Private oDlg As Object
Sub OpenDialog()
Dim oCC 				' ViewController
Dim oViewOnScreen		' com.sun.star.awt.Rectangle
Dim oComponentWindow	
Dim oWindowPosSize		
Dim oToolKitWorkArea	
Dim oTopWindowPosSize	
	DialogLibraries.LoadLibrary("Standard")
	oDlg = CreateUnoDialog(DialogLibraries.Standard.Dialog1)
	
	oCC = ThisComponent.getCurrentController()
	
	REM Full Screen Mode (Except for the top bar)
	oCC.Frame.LayoutManager.HideCurrentUI = false
	
	oViewOnScreen = oCC.VisibleAreaOnScreen
	oComponentWindow = oCC.ComponentWindow
	
	REM A few metrics to help with possible solutions
	With oComponentWindow
		oWindowPosSize		= .getPosSize()
		oToolKitWorkArea	= .Toolkit.WorkArea
		oTopWindowPosSize	= .Toolkit.ActiveTopWindow.getPosSize()
	End With
	
	With oDlg
		.Model.PositionX = oTopWindowPosSize.Width/2 'oViewOnScreen.Width/2
		.Model.PositionY = oTopWindowPosSize.Height/2 'oViewOnScreen.Height/2
		.execute()
		.dispose()
	End With
	
End Sub
========SAMPLE========
Ask_dialog-position-on-screen.ods (12,4,KB)
.
Could someone help me with this?
I’ve even tried the Pythagorean Theorem, without success either. 
 
      
    