首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

vb.net关于鼠标移动的有关问题

2012-01-21 
vb.net关于鼠标移动的问题用SetCursorPos使鼠标移动到指定位置,定义语句如下:Declare Function SetCursorP

vb.net关于鼠标移动的问题
用SetCursorPos使鼠标移动到指定位置,定义语句如下:

Declare Function SetCursorPos Lib "user32" (ByVal x As Long, ByVal y As Long) As Long

用timer控件使鼠标每到一定时间就随机移动到一个位置,代码如下:

  Dim x, y As Integer
  x = 0
  y = 0
  x = Int(1366 * Rnd())
  y = Int(768 * Rnd())

  Call SetCursorPos(x, y)

这个软件是在win7系统下做的,在win7下执行时没有错误,但是在xp系统下执行时Y坐标一直是0,不会变化,这是个什么问题?请各位赐教



[解决办法]
Declare Function SetCursorPos Lib "user32" (ByVal x As integer, ByVal y As integer) As integer
试试
其实用.NET中的Cursor.Position操作可能更简单一些
[解决办法]
Declare Function SetCursorPos Lib "user32" (ByVal x As Integer, ByVal y As Integer) As Integer
API声明改成以上 ,实测可以。
VB6,和VB.NET的API声明有不同,VB.NET我也是初学,印象中一般VB6中声明成Long ,在vb.net中改成Integer就行,
[解决办法]
我的系统环境:XP Professional, sp2 , vb.net 2005,用你的代码,把long 换成 integer
以下代码实测OK

VB.NET code
Public Class Form1    Declare Function SetCursorPos Lib "user32" (ByVal x As [color=#FF0000]Integer[/color], ByVal y As [color=#FF0000]Integer[/color]) As [color=#FF0000]Integer[/color]    Dim x, y As Integer       Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load        x = 0        y = 0        Timer1.Interval = 1000        Timer1.Enabled = True    End Sub    Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick        x = Int(1366 * Rnd())        y = Int(768 * Rnd())        Call SetCursorPos(x, y)    End SubEnd Class
[解决办法]
学习,顶
[解决办法]
学习,学习

热点排行