謝謝你的再現步驟。我能夠重現您的問題。
據我所知,Visual Studio IDE使用Controls而不是Forms。
不知道您的表單的功能是什麼我簡單地在下面添加了一個基本示例來開始。
可以很容易地有很多其他的方式來做到這一點。我不是AddIn開發人員,因此我的知識在這方面有限。
用戶控件
首先,右鍵單擊您的項目,並添加一個新的用戶控件。我在我的例子中命名了我的「MyForm」,並在其上放置了一個簡單的按鈕,單擊時顯示「Hello」。 此用戶控件將成爲您的表單。
namespace MyAddin1
{
public partial class MyForm : UserControl
{
public MyForm()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello");
}
}
}
創建窗體
我們需要使用的承載您的外接程序和您的外接程序的實例的應用程序。 這兩個都是已經在AddIn項目中聲明的成員:_applicationObject和_addInInstance。這些在OnConnection事件中設置。
在下面的代碼中,我創建了一個新的工具窗口,託管我的用戶控件。我正在使用Windows2。CreateTooWindow2方法來做到這一點。
我已將示例代碼添加到Excec事件中,如下所示。再說一遍,我不確定這是否適合它,但是爲了演示代碼,它應該足夠了。
/// <summary>Implements the Exec method of the IDTCommandTarget interface. This is called when the command is invoked.</summary>
/// <param term='commandName'>The name of the command to execute.</param>
/// <param term='executeOption'>Describes how the command should be run.</param>
/// <param term='varIn'>Parameters passed from the caller to the command handler.</param>
/// <param term='varOut'>Parameters passed from the command handler to the caller.</param>
/// <param term='handled'>Informs the caller if the command was handled or not.</param>
/// <seealso class='Exec' />
public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
{
object tempObject = null; // It's required but I'm not sure what one can do with it...
Windows2 windows2 = null; // Reference to the window collection displayed in the application host.
Assembly asm = null; // The assembly containing the user control.
Window myWindow = null; // Will contain the reference of the new Tool Window.
try
{
handled = false;
if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
{
if (commandName == "MyAddin1.Connect.MyAddin1")
{
handled = true;
// Get a reference to the window collection displayed in the application host.
windows2 = (Windows2)_applicationObject.Windows;
// Get the executing assembly.
asm = Assembly.GetExecutingAssembly();
// Create the tool window and insert the user control.
myWindow = windows2.CreateToolWindow2(_addInInstance, asm.Location, "MyAddin1.MyForm", "My Tool Window", "{CB2AE2BD-2336-4615-B0A3-C55B9C7794C9}", ref tempObject);
// Set window properties to make it act more like a modless form.
myWindow.Linkable = false; // Indicates whether the window can be docked with other windows in the IDE or not.
myWindow.IsFloating = true; // Indicates whether the window floats over other windows or not.
// Show the window.
myWindow.Visible = true;
return;
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
我測試了它做我的外接添加到IDE的工具菜單中的應用程序,當我點擊我的外接顯示它的窗口,它的工作。在顯示Assembly對話框時,它也沒有凍結,掛起或者其他任何東西。
我試圖創建簡單的加載項,但無法重現您的問題。你能告訴我們更多關於你的Form1嗎? – tia 2010-09-13 19:02:58
我已經添加了重現步驟。 – JamesMLV 2010-09-14 14:19:04