大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> 程序开发 -> 怎样利用VB限制鼠标移动

怎样利用VB限制鼠标移动

时间: 2021-07-31 作者:daque

正文引见怎样控制鼠标在窗口的指定范畴内挪动。这个本领在须要提防用户鼠标在指定地区内震动时特殊 有效。比方在一个发射游戏中,须要控制鼠标在发射区内挪动。 操纵办法 1、创造一个新工程名目,缺省创造窗体form1 2、增添一个新模体 3、粘贴底下代码到新模体 option explicitdeclare function clipcursor lib "user32" (lprect as any) as long declare function clipcursorclear lib "user32" alias "clipcursor" (byval lprect as long) as long declare function clienttoscreen lib "user32" (byval hwnd as long, lppoint as pointapi) as long type rect left as long top as long right as long bottom as long end type type pointapi x as long y as long end type public retvalue as long public clipmode as boolean public sub setcursor(clipobject as object, setting as boolean) ' used to clip the cursor into the viewport and ' turn off the default windows cursor dim currentpoint as pointapi dim cliprect as rect if setting = false then ' set clip state back to normal retvalue = clipcursorclear(0) exit sub end if ' set current position with currentpoint ..x = 0 ..y = 0 end with ' find position on the screen (not the window) retvalue = clienttoscreen(clipobject.hwnd, currentpoint) ' designate clip area with cliprect ..top = currentpoint.y ..left = currentpoint.x ..right = .left + clipobject.scalewidth ..bottom = .top + clipobject.scaleheight end with ' clip it retvalue = clipcursor(cliprect) end sub 4、增添一个图片框控件(picture1)到窗体(form1) 5、树立picture1的尺寸和form1的一律大 6、在picture1的click事变中增添以次代码: private sub picture1_click() clipmode = not clipmode setcursor picture1, clipmode end sub 7、生存工程名目 8、运路途序。在图片框单击鼠标,鼠标将被包括在图片框控件的地区内。要开释控制状况只需再次单击鼠标。 提防:即使开释控制状况波折,鼠标将被长久控制,只能用从新启用呆板来处置。 另一个控制鼠标震动范畴的本领是封闭鼠标,用其余图象包办光标,比方勃郎宁。

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.