-4
所以我有這段代碼,我需要能夠將光標移動到一個位置,但我需要從列表框中獲取位置,並將光標移動到所有值,移動完成後的項目刪除設置光標位置
Imports System.Drawing.Imaging
Imports System.Runtime.InteropServices
Imports System.Collections.Generic
Public Class Form1
Declare Auto Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As IntPtr)
Const MOUSEEVENTF_LEFTDOWN As Integer = &H2
Const MOUSEEVENTF_LEFTUP As Integer = &H4
Public Declare Auto Function SetCursorPos Lib "User32.dll" (ByVal X As Integer, ByVal Y As Integer) As Long
Public Declare Auto Function GetCursorPos Lib "User32.dll" (ByRef lpPoint As Point) As Long
Public Declare Sub mouse_event Lib "user32" Alias "mouse_event" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_MIDDLEDOWN = &H20 ' middle button down
Public Const MOUSEEVENTF_MIDDLEUP = &H40 ' middle button up
Public Const MOUSEEVENTF_RIGHTDOWN = &H8 ' right button down
Public Const MOUSEEVENTF_RIGHTUP = &H10 ' right button up
Private Declare Function GetPixel Lib "gdi32" (ByVal hdc As Long, ByVal X As Long, ByVal Y As Long) As Long
Private Declare Function GetWindowDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vkey As Long) As Integer
Dim speed As Integer = 1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Dim c As Color
' c = Image.GetPixel()
End Sub
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Dim tempPos As Point
Dim R As Long = GetCursorPos(tempPos)
' Label1.Text = "Mouse helye:" + tempPos.ToString + " :)"
Dim bmp As New Bitmap(80, 80)
' Using bmp As New Bitmap(30, 30)
Using g As Graphics = Graphics.FromImage(bmp)
g.CopyFromScreen(Windows.Forms.Cursor.Position, _
New Point(0, 0), New Size(1, 1))
End Using
Label1.Text = bmp.GetPixel(0, 0).ToString
' Me.Invalidate()
' End Using
If Label1.Text = "Color [A=255, R=0, G=163, B=232]" Then
ListBox1.Items.Add(tempPos.X)
ListBox2.Items.Add(tempPos.Y)
Cursor.Position = New Point(Cursor.Position.X + 20 * speed, Cursor.Position.Y)
Else
Cursor.Position = New Point(Cursor.Position.X + 20 * speed, Cursor.Position.Y)
' If ListBox1.Items.Contains(tempPos.X) And Listbox2.items.contains(tempPos.Y) Then
' Else
' ListBox1.Items.Add(tempPos.X)
' ListBox2.Items.Add(tempPos.Y)
' End If
End If
End Sub
Private Sub Timer2_Tick(sender As Object, e As EventArgs) Handles Timer2.Tick
Dim D As Boolean
Dim S As Boolean
D = GetAsyncKeyState(Keys.D)
S = GetAsyncKeyState(Keys.S)
If S = True Then
Timer1.Start()
End If
If D = True Then
Timer1.Stop()
End If
End Sub
Private Sub Timer3_Tick(sender As Object, e As EventArgs) Handles Timer3.Tick
End Sub
末級
我不明白你想要做什麼...你是什麼意思是_「將光標移動到所有值」_? –
所以有列表框中的值,如「424,203」下一行另一個值,如果我想使用Cursor.Position =新點()我不能只使用listbox1.selecteditem,我需要兩個值,我需要幫助以某種方式修復。我嘗試添加2列表框並單獨保存x,y,但它不起作用。 – Edwinke
所以你試圖獲取列表框項目本身的座標,或者...?你從不爲初學者設置你的'tempPos'變量。 –