成都创新互联网站制作重庆分公司

vb.net鼠标定位 vb定位光标

用VB.NET写一个获取鼠标当前屏幕的坐标.

你好 那因为你放在了Label1控件的移动事件了 。

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:申请域名雅安服务器托管、营销软件、网站建设、天坛街道网站维护、网站推广。

说明:

当前你的代码是在当鼠标经过Label1的MouseMove事件才被激活,其他事件不备激活的。

建议应用函数调用具体方法网上应该有

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

TextBox1.Text = System.Windows.Forms.Cursor.Position.X.ToString "," System.Windows.Forms.Cursor.Position.Y.ToString

End Sub

上面代码我是做过测试才发的,完全能实现你的要求!!!!!!

VB.NET 在RichTextBox中确定鼠标所指的字符位置

void rtf_Click(object s, EventArgs e)

{

MessageBox.Show(rtf.SelectionStart.ToString());

}

在VB.net中怎么获取 鼠标在屏幕中的坐标

Private Declare Function GetCursorPos Lib "user32" (ByRef lpPoint As POINTAPI) As Long '全屏坐标声明

Private Declare Function ScreenToClient Lib "user32.dll" (ByVal hwnd As Int32, ByRef lpPoint As POINTAPI) As Int32 '窗口坐标声明

Private Structure POINTAPI '声明坐标变量

Public x As Int32 '声明坐标变量为32位

Public y As Int32 '声明坐标变量为32位

End Structure

'以上是声明部分

'以下是窗口部分

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick '用时钟控件来取坐标,窗口上放个Timer组件,Enabled为允许,周期为10到100毫秒均可

Dim P As POINTAPI '声明坐标变量

Dim xx, yy '声明转换要用到的变量

GetCursorPos(P) '获取鼠标在屏幕中的位置

ScreenToClient(Me.Handle.ToInt32, P) '转换为本窗体的坐标

xx = P.x.ToString '把X转换成能显示到文本框的字符串格式

yy = P.y.ToString '把Y转换成能显示到文本框的字符串格式

TextBox1.Text = xx + "和" + yy '文本框的内容为X坐标和Y坐标

End Sub

VB.NET改变鼠标位置和让鼠标消失

几乎找不到真正VB.NET的api,都是自己将VB的api改成VB.NET的api,我的理解是声明中对应输入是H的地方保留Long,其他的Long改成Integer,既然VB.NET连MSDN都找不到较全的api说明,不保证api的用法在VB.NET其他版本中适用。

给你个好玩的例子,包括鼠标的隐藏(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鼠标定位 vb定位光标
标题来源:http://cxhlcq.com/article/ddoiejj.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部