简体   繁体   English

部署 Outlook VSTO Addin 后 Win 表单无法打开?

[英]Win form not opening after deploying Outlook VSTO Addin?

I have deployed an Outlook Add-in using Visual Studio Installer project(followed this link) with C#.我已经使用带有 C# 的 Visual Studio 安装程序项目(按照链接)部署了 Outlook 插件。

The setup is getting installed correctly(.msi) and I am able to see it inside Options -> Add-in, also the ribbon is visible with the controls.(It's a winform)安装程序安装正确(.msi),我可以在选项 - >加载项中看到它,功能区也可以通过控件看到。(这是一个winform)

Unfortunately, when I hit the button(inside Ribbon), nothing happens.不幸的是,当我按下按钮(在功能区内)时,什么也没有发生。

Code in Ribbon.cs: Ribbon.cs 中的代码:

private void button1_Click(object sender, RibbonControlEventArgs e)
{
    Form1 formObj = new Form1();

    formObj.FormBorderStyle = FormBorderStyle.FixedDialog;

    formObj.MaximizeBox = false;

    formObj.MinimizeBox = false;

    formObj.StartPosition = FormStartPosition.CenterScreen;

    //formObj.ShowDialog();
    formObj.Show();
}

The code is working fine while debugging solution.调试解决方案时代码运行良好。

I searched but found nothing related.我搜索但没有发现任何相关内容。 What can be the issue here or I am missing something?这里可能是什么问题,或者我遗漏了什么?

Regards, Ank问候, 安克

Most probably your form is displayed behind the Outlook window.很可能您的表单显示在 Outlook window 后面。 To get it visible on top of Outlook windows you must specify the parent window handle.要使其在 Outlook windows 顶部可见,您必须指定父 window 句柄。 You can retrieve it by casting the Outlook window instance like Explorer or Inspector to the IOLEWindow interface and using the IOleWindow::GetWindow method which retrieves a handle to one of the windows participating in in-place activation (frame, document, parent, or in-place object window). You can retrieve it by casting the Outlook window instance like Explorer or Inspector to the IOLEWindow interface and using the IOleWindow::GetWindow method which retrieves a handle to one of the windows participating in in-place activation (frame, document, parent, or in -放置 object 窗口)。

The Show or ShowDialog method accepts an instance of the IWin32Window interface which represents your parent window handle. ShowShowDialog方法接受IWin32Window接口的一个实例,该接口代表您的父 window 句柄。

 /// <summary>
 /// Implemented and used by containers and objects to obtain window handles 
 /// and manage context-sensitive help.
 /// </summary>
 /// <remarks>
 /// The IOleWindow interface provides methods that allow an application to obtain  
 /// the handle to the various windows that participate in in-place activation, 
 /// and also to enter and exit context-sensitive help mode.
 /// </remarks>
 [ComImport]
 [Guid("00000114-0000-0000-C000-000000000046")]
 [InterfaceType (ComInterfaceType.InterfaceIsIUnknown)]
 public interface IOleWindow
 {
     /// <summary>
     /// Returns the window handle to one of the windows participating in in-place activation 
     /// (frame, document, parent, or in-place object window).
     /// </summary>
     /// <param name="phwnd">Pointer to where to return the window handle.</param>
     void GetWindow (out IntPtr phwnd) ;

     /// <summary>
     /// Determines whether context-sensitive help mode should be entered during an 
     /// in-place activation session.
     /// </summary>
     /// <param name="fEnterMode"><c>true</c> if help mode should be entered; 
     /// <c>false</c> if it should be exited.</param>
     void ContextSensitiveHelp ([In, MarshalAs(UnmanagedType.Bool)] bool fEnterMode) ;
 }

 public IWin32Window  getWindowHandle()
 {
        dynamic activeWindow = Globals.ThisAddIn.Application.ActiveWindow();
        IOleWindow win = activeWindow as IOleWindow;
        window = win.GetWindow();        
        IWin32Window wind = Control.FromHandle(window);

        return wind;
 }

// and pass it to the Show method

form.Show(getWindowHandle());

I got the issue here.我在这里得到了问题。

Actually I have a dependency for win form(Materialskin.dll), which was excluded from the detected dependecies(inside setup project), as mentioned in the tutorial.实际上,如教程中所述,我对 win 表单(Materialskin.dll)有一个依赖项,该依赖项已从检测到的依赖项(安装项目内部)中排除。

I changed the exclude property value to false only for Materialskin.dll and rebuild the solution.我仅将 Materialskin.dll 的 exclude 属性值更改为 false 并重建解决方案。

After successful installation of created msi package, the Addin is working fine.成功安装创建的 msi package 后,插件工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM