【问题标题】:Create Visual Studio plugin to launch window form application inside visual studio(not standalone)创建 Visual Studio 插件以在 Visual Studio 中启动窗口窗体应用程序(非独立)
【发布时间】:2017-08-09 07:16:36
【问题描述】:

我有一个当前正在运行的基于窗口的工具。我需要将此工具添加为 Visual Studio 中的插件/扩展。因此,如果用户安装了 Visual Studio,则可以从 Visual Studio 菜单中打开此工具。当从 Visual Studio 打开时,它应该在 Visual Studio 中作为模型对话框打开而不是单独的应用程序(因为我们使用 process.start 打开)。请提出相同的建议。 谢谢。

【问题讨论】:

标签: c# winforms visual-studio plugins visual-studio-extensions


【解决方案1】:

根据您的描述,我认为您可以使用自定义工具窗口来实现它。欲了解更多信息,请参阅: https://msdn.microsoft.com/en-us/library/cc138567.aspx

从 Visual Studio 2010 开始,工具窗口本身基于 WPF 技术,尽管它们仍然为 WinForms 组件的托管提供向后兼容性。

如果您使用Winform Control,请参考以下代码。

namespace TWToolbar
{
    using System;
    using System.Runtime.InteropServices;
    using Microsoft.VisualStudio.Shell;
    using System.ComponentModel.Design;
    using System.Collections.Generic;


    /// <summary>
    /// This class implements the tool window exposed by this package and hosts a user control.
    /// </summary>
    /// <remarks>
    /// In Visual Studio tool windows are composed of a frame (implemented by the shell) and a pane,
    /// usually implemented by the package implementer.
    /// <para>
    /// This class derives from the ToolWindowPane class provided from the MPF in order to use its
    /// implementation of the IVsUIElementPane interface.
    /// </para>
    /// </remarks>
    [Guid("1a24c96c-30bd-466b-8315-14bf54e4f17a")]
    public class TestToolWindow : ToolWindowPane
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="TestToolWindow"/> class.
        /// </summary>
        /// 
        public UserControl1 control;
        public TestToolWindow() : base(null)
        {
            this.Caption = "TestToolWindow";
         // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
            // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
            // the object returned by the Content property.
            this.control = new UserControl1();//new TestToolWindowControl(users);
       }

        override public System.Windows.Forms.IWin32Window Window
        {
            get
            {
                return (System.Windows.Forms.IWin32Window)control;
            }
        }
    }
}

示例项目:https://1drv.ms/u/s!AlvaNEnglADDgRMFqXKjdb63OeeK

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    相关资源
    最近更新 更多