【问题标题】:Set Window Position in VB relative to another application相对于另一个应用程序在 VB 中设置窗口位置
【发布时间】:2014-02-25 11:34:13
【问题描述】:

在 Visual Basic 中有没有办法让我将应用程序的窗口相对于另一个正在运行的 .EXE 的位置定位?

我想将我的 Windows 右侧对齐到另一侧的左侧。

【问题讨论】:

  • 是的,这当然是可能的。请向我们展示您迄今为止所做的尝试。

标签: vb.net


【解决方案1】:

您可以使用GetWindowRect

检索指定的边界矩形的尺寸 窗口。

然后:

Public Class Form1

    ''' <summary>
    ''' Retrieves the dimensions of the bounding rectangle of the specified window. 
    ''' </summary>
    <System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint:="GetWindowRect")>
    Shared Function GetWindowRectangle(
           ByVal [Handle] As IntPtr,
           ByRef [Rectangle] As Rectangle
    ) As Boolean
    End Function

    Private Shadows Sub Load() Handles MyBase.Load

        Dim rect As New Rectangle
        Dim hwnd As IntPtr = Process.GetProcessesByName("notepad").First.MainWindowHandle

        GetWindowRectangle(hwnd, rect)

        Me.Location = New Point(rect.X - Me.Height, rect.Y)

    End Sub

End Class

如果您想在外部进程移动/调整大小时保持位置,那么您可以添加计时器或其他技术来验证窗口位置。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-24
    • 2011-01-27
    • 1970-01-01
    • 1970-01-01
    • 2021-03-13
    • 2013-07-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多