【发布时间】:2014-02-25 11:34:13
【问题描述】:
在 Visual Basic 中有没有办法让我将应用程序的窗口相对于另一个正在运行的 .EXE 的位置定位?
我想将我的 Windows 右侧对齐到另一侧的左侧。
【问题讨论】:
-
是的,这当然是可能的。请向我们展示您迄今为止所做的尝试。
标签: vb.net
在 Visual Basic 中有没有办法让我将应用程序的窗口相对于另一个正在运行的 .EXE 的位置定位?
我想将我的 Windows 右侧对齐到另一侧的左侧。
【问题讨论】:
标签: vb.net
您可以使用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
如果您想在外部进程移动/调整大小时保持位置,那么您可以添加计时器或其他技术来验证窗口位置。
【讨论】: