寻找应用程序的中心 - VB.net

时间:2013-03-01 21:59:39

标签: vb.net

我想找到我的申请中心。请在说Me.Width / 2 ..

之前阅读

我正在加载一个包含基于Java的应用程序的网页,并希望在页面加载后自动点击“登录”按钮。 VB应用程序是一个设置大小,但不会最大化,允许用户在屏幕上移动应用程序。我在想的是做了......

SetCursorPos({CenterOfApp.Width} + 20, {CenterOfApp.Height})

..然后模拟鼠标点击。

帮助将不胜感激,谢谢!

编辑1 - 我相信答案可能在下面,我只是不确定所需的公式。我再次说,这是一个固定大小的VB.net应用程序,加载固定大小的Java应用程序抛出VB.net浏览器控件。该按钮将始终位于VB.net应用程序的相同位置,但VB.net应用程序将不会始终位于计算机屏幕的同一位置。意思是,我需要根据计算机屏幕上的位置找到VB.net应用程序的中心。

Dim ScreenWidth As Integer = Screen.PrimaryScreen.Bounds.Width
Dim ScreenHeight As Integer = Screen.PrimaryScreen.Bounds.Height
Dim ClientLeft As Integer = Me.Location.X
Dim LeftOfScreenToApp As Integer ' This is to be the distance from the left side of the screen to the left side of the VB app.
LeftOfScreenToApp = ...
SetCursorPos(LeftOfScreenToApp + (Me.Width / 2) + 20, Me.Height / 2)

1 个答案:

答案 0 :(得分:0)

碰巧我只是忽略了Me.Location.X是从VB.net应用程序左边的屏幕左侧偏移的事实,所以..

Dim LeftOfScreenToLeftOfApp As Integer = Me.Location.X
Dim MiddleOfApp As Integer = LeftOfScreenToLeftOfApp + Me.Width / 2

..获取应用程序的中心,无论它位于屏幕上的哪个位置。