Reputation: 57
I have created an Add-In for Outlook using WPF. Everything is working correctly, except for the "Flare." When the WPF Window opens, it's not being centered on the Outlook form, it opens centered on the screen. I have the WindowStartLocation set to CenterOwner, but this doesn't seem to be doing the trick.
Upvotes: 0
Views: 990
Reputation: 115
Ran across this looking for a VBA answer- in its simplest form, where application is the host and me is the shortcut to the current form.
Private Sub UserForm_Initialize()
ProgressFrame.Caption = ""
Me.Left = Application.ActiveWindow().Left + Application.ActiveWindow().Width / 2 - (Me.Width / 2)
Me.Top = Application.ActiveWindow().Top + Application.ActiveWindow().Height / 2 - (Me.Height / 2)
End Sub
Upvotes: 0
Reputation: 57
My solution, with guidance from Cory:
var sendToPulse = new Pulse_Outlook_Presentation.SendToPulse ();
var interopApplication = Globals.ThisAddIn.Application;
var x = (interopApplication.ActiveWindow ().Left + interopApplication.ActiveWindow ().Width / 2) - (sendToPulse.Width / 2);
var y = (interopApplication.ActiveWindow ().Top + interopApplication.ActiveWindow ().Height / 2) - (sendToPulse.Height / 2);
OutlookWin32Window parentWindow = new OutlookWin32Window (Globals.ThisAddIn.Application.ActiveWindow ());
sendToPulse.Left = x;
sendToPulse.Top = y;
Upvotes: 2
Reputation: 7468
You should be able to get a reference to the current instance of Outlook, access the Application object for that instance and get the Window size, and location (Left, Top) and do some math to get the positioning for your window.
Something akin to:
Dim interopApplication As Outlook.Application = _
Me.ActiveExplorer().Application
With interopApplication.ActiveWindow
Dim _left = Me.Width - (.Width / 2)
Dim _top = Me.Height - (.Height / 2)
End With
This supposes that the Outlook window is on the first monitor and is maximized. Some more logic will have to be written to take care of other contingencies
Upvotes: 0