表单一旦丢失就无法获得焦点
我已经为 Visual Studio 2008 创建了一个加载项,可以使用以下命令打开一个表单 Form1.Show(this);
如果(在表单打开时)用户打开/关闭 Visual Studio 对话框(例如程序集信息),则用户无法将注意力重新集中在由插件。
我是否缺少某些内容来允许用户返回表单?如果我使用 Form1.ShowDialog(this)
,则不会发生这种情况,但我希望用户在自定义表单打开时看到程序集信息。
该加载项使用
public System.IntPtr Handle
{
get
{
return new System.IntPtr(_applicationObject.MainWindow.HWnd);
}
}
编辑实现 IWin32Window
:重现步骤
public void Exec(...)
System.Windows.Forms.Form f = new System.Windows.Forms.Form();
f.Show();
I have created an Add-In for Visual Studio 2008 that opens up a form, usingForm1.Show(this);
If (while the form is open) the user opens/closes a Visual Studio dialog box, (such as Assembly Information) then the user cannot focus back on the form created by the addin.
Is there something I'm missing to allow the user to return to the form? This doesn't occur if I use Form1.ShowDialog(this)
, but I would like the user to see the Assembly Information while my custom form is open.
The add-in implements IWin32Window
using
public System.IntPtr Handle
{
get
{
return new System.IntPtr(_applicationObject.MainWindow.HWnd);
}
}
EDIT: Steps to reproduce
public void Exec(...)
System.Windows.Forms.Form f = new System.Windows.Forms.Form();
f.Show();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
感谢您的复制步骤。我能够重现您的问题。
据我所知,Visual Studio IDE 使用控件而不是表单。
不知道您的表单的预期功能是什么,我只是在下面添加了一个基本示例来开始。
很容易有许多其他方法可以做到这一点。我不是插件开发人员,因此我在该领域的知识有限。
用户控件
首先,右键单击您的项目并添加一个新的用户控件。我在示例中将其命名为“MyForm”,并在其上放置了一个简单的按钮,单击时显示“Hello”。
该用户控件将成为您的表单。
创建表单
我们需要使用托管您的外接程序和外接程序实例的应用程序。
这两个都是已在您的 AddIn 项目中声明的成员:_applicationObject 和 _addInInstance。这些是在 OnConnection 事件中设置的。
在下面的代码中,我创建了一个新的工具窗口,在其中托管我的用户控件。我正在使用 Windows2.CreateTooWindow2 方法来执行此操作。
我已将示例代码添加到 Excec 事件中,如下所示。再说一次,我不确定这是否是合适的地方,但对于演示代码来说它应该足够了。
我测试了该应用程序,它确实将我的外接程序添加到 IDE 的工具菜单中,当我单击我的外接程序时,它显示了该窗口并且它可以工作。显示装配对话框时也没有冻结、挂起或任何其他情况。
Thank you for the reproduction steps. I was able to reproduce your issue.
As far as I was able to find out, the Visual Studio IDE uses Controls rather than Forms.
Not knowing what the intended functionality is of your form I simply added a basic example below to get started.
There could easily be many other ways of doing this. I'm no AddIn developer and as such my knowledge is limited in that area.
The User Control
First, right-click your project and add a new user control. I named mine "MyForm" in my example and placed a simple button on it, displaying "Hello" when clicked.
This user control is going to be your form.
Creating the Form
We need to use the application which is hosting your AddIn and the instance of your AddIn.
Both those are members already declared in your AddIn project: _applicationObject and _addInInstance. Those are set in the OnConnection event.
In the below code I create a new tool window, hosting my user control in it. I'm using the Windows2.CreateTooWindow2 Method to do that.
I have added my sample code into the Excec event as seen below. Again, I'm not sure if that is the right place for it but for demonstrating the code it should suffice.
I tested the application it did add my add-in to the tools menu of the IDE and when I clicked my Addin it showed the window and it worked. It also did not freeze, hang or anything when showing the Assembly Dialog.
也许这些讨论可能会有所帮助?
我可以将 ShowDialog() 设置为不在最顶层吗?
如何获取句柄WinForm 应用程序中最顶层的表单?
Perhaps these discussions might help?
Can I set ShowDialog() to not be topmost?
How to get the handle of the topmost form in a WinForm app?