【问题标题】:Bringing ToolWindow to Front of Application将 ToolWindow 置于应用程序前面
【发布时间】:2015-05-17 11:45:47
【问题描述】:

基本上,在我的代码中,我将表单转换为加载事件中的工具窗口:

Dim lStyleEx As Long = win32.WS._EX_TOOLWINDOW
Call SetWindowLong(Handle, win32.GWL.__EXSTYLE, CInt(lStyleEx))
Const swpFlags As Long = _
        win32.SWP._FRAMECHANGED Or _
        win32.SWP._NOMOVE Or _
        win32.SWP._NOSIZE Or _
        win32.SWP._NOZORDER
Call SetWindowPos(Handle, CType(0, IntPtr), 0, 0, 0, 0, CType(swpFlags, win32.SetWindowPosFlags))

(我有一个包含所有常量枚举的类 win32)

现在,我想使用 IVsWindowFrame.Show() 将此工具窗口置于最前面,但我无法为我的表单获取实际的 IVsWindowFrame。在网上搜索后,我在 MSDN 论坛上找到了一个 sn-p,但在转换为 VBA 之后出现了各种问题,例如我不知道如何正确创建一个新的 ServiceProvider:

Dim shell As IVsUIShell = DirectCast(ServiceProvider.GetService(GetType(SVsUIShell)), IVsUIShell)
Dim frame As IVsWindowFrame
Dim guid As New Guid(ToolWindow.GuidList.guidToolWindowPersistanceString)
shell.FindToolWindow(CUInt(__VSFINDTOOLWIN.FTW_fForceCreate), guid, frame)
frame.Show()

来自https://social.msdn.microsoft.com/Forums/vstudio/en-US/d6c2b85c-3a48-48f7-a9f6-a68ea4ef0441/how-to-get-access-to-my-toolwindowpane-object-with-an-ivswindowframe-pointer?forum=vsx

任何有关查找表单的 IVsUIShell 的帮助或对此代码的解释将不胜感激!

我还尝试了一些简单的方法,例如将实际表单设置为 IVsWindowFrame:

Dim windowFrame As IVsWindowFrame = CType(Me, IVsWindowFrame)
windowFrame.Show()

但它会抛出异常:

type 'RifleSystem.scrSettings' to type 'Microsoft.VisualStudio.Shell.Interop.IVsWindowFrame'.

顺便说一句,如果有帮助,我正在运行 64 位 VS2013。

【问题讨论】:

    标签: vb.net vba


    【解决方案1】:

    好吧,我现在觉得自己很愚蠢。有一个属性 Form.Owner 正是我在这种情况下所需要的,它完美地工作!不需要所有这些令人费解的东西:D

    如果有人感兴趣,请点击以下链接:

    https://msdn.microsoft.com/en-us/library/system.windows.forms.form.owner%28v=vs.110%29.aspx

    【讨论】:

      猜你喜欢
      • 2012-07-26
      • 2017-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-16
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多