我们专注攀枝花网站设计 攀枝花网站制作 攀枝花网站建设
成都网站建设公司服务热线:400-028-6601

网站建设知识

十年网站开发经验 + 多家企业客户 + 靠谱的建站团队

量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决

vb.net自定义光标 vb中将光标定位在文本框

vb.net如何更换程序光标

比如你要更换在你某个窗体上的光标。

剑河ssl适用于网站、小程序/APP、API接口等需要进行数据传输应用场景,ssl证书未来市场广阔!成为创新互联建站的ssl证书销售渠道,可以享受市场价格4-6折优惠!如果有意向欢迎电话联系或者加微信:18982081108(备注:SSL证书合作)期待与您的合作!

那么在这个窗体内用这样的代码

Me.Cursor = System.Windows.Forms.Cursors.Cross

如果你要更换当前系统显示的光标

System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Cross

其中Cross代表十字光标,你也可以更改成其他的,直接查看Cursors中的各成员就可以找到了。

VB.net,DataGridView焦点跟光标

代码如下:

Private Sub DataGridView1_CellMouseEnter(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellMouseEnter

DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect

Dim r As DataGridViewRow

For Each r In DataGridView1.SelectedRows

r.Selected = False

Next

If e.RowIndex -1 Then

DataGridView1.Rows.Item(e.RowIndex).Selected = True

End If

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://mswzjz.cn/article/dojjdcj.html

其他资讯