幾乎找不到真正VB.NET的api,都是自己將VB的api改成VB.NET的api,我的理解是聲明中對(duì)應(yīng)輸入是H的地方保留Long,其他的Long改成Integer,既然VB.NET連MSDN都找不到較全的api說明,不保證api的用法在VB.NET其他版本中適用。
創(chuàng)新互聯(lián)公司是一家專業(yè)提供長白企業(yè)網(wǎng)站建設(shè),專注與網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè)、H5頁面制作、小程序制作等業(yè)務(wù)。10年已為長白眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。
給你個(gè)好玩的例子,包括鼠標(biāo)的隱藏(Ctrl_↓)、顯示(Ctrl_↑),移動(dòng)、點(diǎn)擊
在Form1上放上2個(gè)TextBox,其中TextBox1.Multiline = True,并且面積大些,2個(gè)Button,運(yùn)行后在TextBox1中點(diǎn)擊一下會(huì)記錄位置,移開鼠標(biāo),點(diǎn)擊移動(dòng)或點(diǎn)擊Button,可模擬在TextBox1中的點(diǎn)擊
Public Class Form1
Public My_MousePosition As Point
'模擬鼠標(biāo)移動(dòng)、點(diǎn)擊
Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
'定義光標(biāo)的位置
Declare Function SetCursorPos Lib "user32" Alias "SetCursorPos" (ByVal x As Integer, ByVal y As Integer) As Integer
'鼠標(biāo)的隱藏
Declare Function ShowCursor Lib "user32" Alias "ShowCursor" (ByVal bShow As Integer) As Integer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TextBox1.Multiline = True
Button1.Text = "點(diǎn)擊"
Button2.Text = "移動(dòng)"
Me.KeyPreview = True
End Sub
Private Sub Form1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.Control And e.KeyCode = Keys.Down Then ShowCursor(0)
If e.Control And e.KeyCode = Keys.Up Then ShowCursor(1)
End Sub
Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
TextBox2.Text = MousePosition.X " " MousePosition.Y
End Sub
Private Sub TextBox1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles TextBox1.MouseClick
My_MousePosition = MousePosition
TextBox1.Text = My_MousePosition.X " " My_MousePosition.Y vbCrLf
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SetCursorPos(My_MousePosition.X, My_MousePosition.Y)
mouse_event(H2, 0, 0, 0, 0)
mouse_event(H4, 0, 0, 0, 0)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
SetCursorPos(My_MousePosition.X, My_MousePosition.Y)
End Sub
End Class
其中
mouse_event Lib "user32" (ByVal dwFlags As Long
的dwFlags的代碼是
Const MOUSEEVENTF_LEFTDOWN = H2
Const MOUSEEVENTF_LEFTUP = H4
Const MOUSEEVENTF_MIDDLEDOWN = H20
Const MOUSEEVENTF_MIDDLEUP = H40
Const MOUSEEVENTF_MOVE = H1
Const MOUSEEVENTF_ABSOLUTE = H8000
Const MOUSEEVENTF_RIGHTDOWN = H8
Const MOUSEEVENTF_RIGHTUP = H10
調(diào)用api
在Visual Baisc.net中的聲明:
Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Long, ByVal dx As Long, ByVal dy As Long, ByVal cButtons As Long, ByVal dwExtraInfo As Long)
Public Const MOUSEEVENTF_LEFTDOWN = H2 '模擬鼠標(biāo)左鍵按下
Public Const MOUSEEVENTF_LEFTUP = H4 ’模擬鼠標(biāo)左鍵釋放
Public Const MOUSEEVENTF_MIDDLEDOWN = H20 '模擬鼠標(biāo)中間鍵按下
Public Const MOUSEEVENTF_MIDDLEUP = H40 '模擬鼠標(biāo)中間鍵釋放
Public Const MOUSEEVENTF_RIGHTDOWN = H8 '模擬鼠標(biāo)右鍵按下
Public Const MOUSEEVENTF_RIGHTUP = H10 '模擬鼠標(biāo)右鍵釋放
Public Const MOUSEEVENTF_MOVE = H1 '模擬鼠標(biāo)指針移動(dòng)
例:
mouse_event MOUSEEVENTF_LEFTDOWN,10,10,0,0
'在(10,10)模擬鼠標(biāo)左鍵按下
一種方法是模擬移動(dòng)鼠標(biāo)移動(dòng),一種是獲取窗口里的控件直接輸入
將RTF的Padding設(shè)置比較大,例如10,此時(shí)我發(fā)現(xiàn)鼠標(biāo)移動(dòng)到RTF的邊緣部分的時(shí)候(不超過Padding的范圍),滾動(dòng)條就能夠顯示,一旦鼠標(biāo)移動(dòng)到Content里面的時(shí)候,滾動(dòng)條就不顯示
1、滾動(dòng)條分為水平滾動(dòng)條(HSCROLLBAR)和垂直滾動(dòng)條(VSCROLLBAR)兩種,可以作為輸入設(shè)備或者速度、數(shù)量的指示器來使用.
2、基本屬性:object.max[=value],object.min[=value],最大最小范圍 object.value[=value],
控件是可以顯示在里面的,你只要加個(gè)label,把label的屬性設(shè)為visualble=fause就行。設(shè)置鼠標(biāo)經(jīng)過頭像的mouseHover和mouseLeave事件,當(dāng)mouseHover時(shí)label的屬性visualble=true,當(dāng)mouseLeave時(shí)label的屬性visualble=fause即可。窗體的鼠標(biāo)事件可以設(shè)置控件的cursor屬性,里面可以選擇許多種鼠標(biāo)圖形。 只要是正常的Form都可以改變窗體大小,但是無邊框的窗體只能用函數(shù)改變或者設(shè)置屬性,在debug后是不能改變的。拖動(dòng)窗體需要在窗體的load時(shí)間里面寫入當(dāng)鼠標(biāo)單擊不放時(shí)的事件即可,不難。