vb.net移动鼠标 vbs控制鼠标
VB.NET改变鼠标位置和让鼠标消失
几乎找不到真正VB.NET的api,都是自己将VB的api改成VB.NET的api,我的理解是声明中对应输入是H的地方保留Long,其他的Long改成Integer,既然VB.NET连MSDN都找不到较全的api说明,不保证api的用法在VB.NET其他版本中适用。
创新互联公司是一家专业提供长白企业网站建设,专注与网站建设、成都网站建设、H5页面制作、小程序制作等业务。10年已为长白众多企业、政府机构等服务。创新互联专业网站建设公司优惠进行中。
给你个好玩的例子,包括鼠标的隐藏(Ctrl_↓)、显示(Ctrl_↑),移动、点击
在Form1上放上2个TextBox,其中TextBox1.Multiline = True,并且面积大些,2个Button,运行后在TextBox1中点击一下会记录位置,移开鼠标,点击移动或点击Button,可模拟在TextBox1中的点击
Public Class Form1
Public My_MousePosition As Point
'模拟鼠标移动、点击
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)
'定义光标的位置
Declare Function SetCursorPos Lib "user32" Alias "SetCursorPos" (ByVal x As Integer, ByVal y As Integer) As Integer
'鼠标的隐藏
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 = "点击"
Button2.Text = "移动"
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
如何在VB.net中用程序控制鼠标移动和点击
调用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 '模拟鼠标左键按下
Public Const MOUSEEVENTF_LEFTUP = H4 ’模拟鼠标左键释放
Public Const MOUSEEVENTF_MIDDLEDOWN = H20 '模拟鼠标中间键按下
Public Const MOUSEEVENTF_MIDDLEUP = H40 '模拟鼠标中间键释放
Public Const MOUSEEVENTF_RIGHTDOWN = H8 '模拟鼠标右键按下
Public Const MOUSEEVENTF_RIGHTUP = H10 '模拟鼠标右键释放
Public Const MOUSEEVENTF_MOVE = H1 '模拟鼠标指针移动
例:
mouse_event MOUSEEVENTF_LEFTDOWN,10,10,0,0
'在(10,10)模拟鼠标左键按下
VB.net中怎么将鼠标移动到相对某个窗体的某个位置
一种方法是模拟移动鼠标移动,一种是获取窗口里的控件直接输入
vb.net当鼠标移到边界时滚动条
将RTF的Padding设置比较大,例如10,此时我发现鼠标移动到RTF的边缘部分的时候(不超过Padding的范围),滚动条就能够显示,一旦鼠标移动到Content里面的时候,滚动条就不显示
1、滚动条分为水平滚动条(HSCROLLBAR)和垂直滚动条(VSCROLLBAR)两种,可以作为输入设备或者速度、数量的指示器来使用.
2、基本属性:object.max[=value],object.min[=value],最大最小范围 object.value[=value],
VB.net怎么实现运行时鼠标拖动改变控件的大小啊
控件是可以显示在里面的,你只要加个label,把label的属性设为visualble=fause就行。设置鼠标经过头像的mouseHover和mouseLeave事件,当mouseHover时label的属性visualble=true,当mouseLeave时label的属性visualble=fause即可。窗体的鼠标事件可以设置控件的cursor属性,里面可以选择许多种鼠标图形。 只要是正常的Form都可以改变窗体大小,但是无边框的窗体只能用函数改变或者设置属性,在debug后是不能改变的。拖动窗体需要在窗体的load时间里面写入当鼠标单击不放时的事件即可,不难。
名称栏目:vb.net移动鼠标 vbs控制鼠标
本文网址:http://azwzsj.com/article/hjisdj.html