Center Outlook WPF Add-In

╄→尐↘猪︶ㄣ 提交于 2019-12-08 13:13:58

问题


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.


回答1:


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




回答2:


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;



回答3:


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


来源:https://stackoverflow.com/questions/4765005/center-outlook-wpf-add-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!