我正在尝试获取图片或更具体的动画,以便在整个计算机上跟踪鼠标,而不仅仅是在表单内部。我找到了这段代码
Public Class Form1
Private Sub Form1_MouseMove(ByVal sender As Object, _
ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles Me.MouseMove
PictureBox1.Top = MousePosition.Y - Me.Top
PictureBox1.Left = MousePosition.X - Me.Left
End Sub
结束班
这花花公子所以现在我想在没有表格的情况下这样做。
非常感谢任何帮助。
答案 0 :(得分:0)
你不能真正抛弃表格,但你可以绕过它。创建表单,将Borderstyle设置为none,将TopMost设置为true。添加Picturebox并将图片框的.Dock属性设置为All 使用我的代码中的计时器是因为我们将使表单点击,然后Mouseevents将无法正常工作。
使用以下代码使表单跟随鼠标光标。
Public Class Form1
<System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint:="GetWindowLong")> Public Shared Function GetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer) As Integer
End Function
<System.Runtime.InteropServices.DllImport("user32.dll", EntryPoint:="SetWindowLong")> Public Shared Function SetWindowLong(ByVal hWnd As IntPtr, ByVal nIndex As Integer, ByVal dwNewLong As Integer) As Integer
End Function
Const xOff As Integer = 0 'How far the form will be away from the curson in x-direction
Const yOff As Integer = 0 'How far the form will be away from the curson in y-direction
Private WithEvents Timer1 As Timer
Private Sub Timer1_Tick(sender As Object, e As EventArgs)
Me.SetDesktopLocation(MousePosition.X - xOff, MousePosition.Y - yOff) 'Set the form's position
End Sub
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'Setup a timer
Timer1 = New Timer
Timer1.Interval = 1
AddHandler Timer1.Tick, AddressOf Timer1_Tick
Timer1.Start()
'Set the form to clickthrough
'See http://stackoverflow.com/questions/18294658/vb-net-click-through-form
Dim InitialStyle As Integer
InitialStyle = GetWindowLong(Me.Handle, -20)
SetWindowLong(Me.Handle, -20, InitialStyle Or &H80000 Or &H20) 'Makes the window "click-throughable"
End Sub
End Class
其他TopMost-windows和通过任务栏切换程序有问题,但这是一个开始。