Respecting WinForm StartPosition

Add-in Express™ Support Service
That's what is more important than anything else

Respecting WinForm StartPosition
 
Stephane Zanoni




Posts: 9
Joined: 2010-12-13
I'm launching a new form in order to display some UI settings. This is not an "Outlook Form", but instead a classic WinForm. I've read other posts that seem to suggest this is possible.

However, the StartPosition does not work, the form will sometimes show on the wrong screen.


this.StartPosition = FormStartPosition.CenterParent;


Based on other posts, I've tried using the WindowWrapper and are trying to use the GetOutlookWindowHandle, but it still doesn't appear to work.


IntPtr parentIntptr = IntPtr.Zero;
try
{
    object inspector = AddinModule.CurrentInstance.OutlookApp.ActiveInspector();
    inspector = inspector ?? AddinModule.CurrentInstance.OutlookApp.ActiveWindow();
    parentIntptr = AddinModule.CurrentInstance.GetOutlookWindowHandle(inspector);
}
catch { }

WindowWrapper parentWindow = new WindowWrapper(parentIntptr);

this.Show(parentWindow);


How can I troubleshoot? I've added logging and parentIntPtr is != 0.
Posted 28 Jul, 2015 21:14:38 Top
nwein




Posts: 577
Joined: 2011-03-28
My best recommendation for you is to use the form as a dialog. Then you can set the form's location as CentralParent and you don't have to worry about getting the handle of your host.
If you don't want the form to be a dialog and block interactions with the host while it's open, then it gets tricky.
I've just cracked open my code to see how I'm doing it and, boy, it's not nice.
I have it working flawlessly, but again, very complicated using a lot of windows API calls, but perhaps Andrei can find a simpler way.
Bottom line - dialog is probably the best way to go (if not, then you have to make sure your form is modal anyway, otherwise users might miss it as the host can get "in front" of your form)
Posted 29 Jul, 2015 10:48:10 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Thank you, Nir!

Hello Stephane,

Does Nir's suggestion help? If not, I recommend that you google for a solution; the issue doesn't seem to relate to Add-in Express.


Andrei Smolin
Add-in Express Team Leader
Posted 30 Jul, 2015 08:57:33 Top