C#限制鼠标移动范围.doc

上传人:豆**** 文档编号:29958010 上传时间:2022-08-02 格式:DOC 页数:12 大小:200KB
返回 下载 相关 举报
C#限制鼠标移动范围.doc_第1页
第1页 / 共12页
C#限制鼠标移动范围.doc_第2页
第2页 / 共12页
点击查看更多>>
资源描述

《C#限制鼠标移动范围.doc》由会员分享,可在线阅读,更多相关《C#限制鼠标移动范围.doc(12页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。

1、1一个鼠标类#region一个鼠标类2/*/3/MouseControl4/MadebyMichael5/date2008-01-306/7classMouse89internalconstbyteSM_MOUSEPRESENT=19;10internalconstbyteSM_CMOUSEBUTTONS=43;11internalconstbyteSM_MOUSEWHEELPRESENT=75;1213internalstructPOINTAPI1415internalintx;16internalinty;171819internalstructRECT2021internalintlef

2、t;22internalinttop;23internalintright;24internalintbottom;252627System.Runtime.InteropServices.DllImport(user32.dll,EntryPoint=SwapMouseButton)28internalexternstaticintSwapMouseButton(intbSwap);2930System.Runtime.InteropServices.DllImport(user32,EntryPoint=ClipCursor)31internalexternstaticintClipCur

3、sor(refRECTlpRect);3233System.Runtime.InteropServices.DllImport(user32.dll,EntryPoint=GetCursorPos)34internalexternstaticintGetCursorPos(refPOINTAPIlpPoint);3536System.Runtime.InteropServices.DllImport(user32.dll,EntryPoint=ShowCursor)37internalexternstaticboolShowCursor(boolbShow);3839System.Runtim

4、e.InteropServices.DllImport(user32.dll,EntryPoint=EnableWindow)40internalexternstaticintEnableWindow(inthwnd,intfEnable);4142System.Runtime.InteropServices.DllImport(user32.dll,EntryPoint=GetWindowRect)43internalexternstaticintGetWindowRect(inthwnd,refRECTlpRect);4445System.Runtime.InteropServices.D

5、llImport(user32.dll,EntryPoint=SetCursorPos)46internalexternstaticintSetCursorPos(intx,inty);4748System.Runtime.InteropServices.DllImport(user32.dll,EntryPoint=GetSystemMetrics)49internalexternstaticintGetSystemMetrics(intnIndex);5051System.Runtime.InteropServices.DllImport(user32.dll,EntryPoint=Set

6、DoubleClickTime)52internalexternstaticintSetDoubleClickTime(intwCount);5354System.Runtime.InteropServices.DllImport(user32.dll,EntryPoint=GetDoubleClickTime)55internalexternstaticintGetDoubleClickTime();5657System.Runtime.InteropServices.DllImport(kernel32.DLL,EntryPoint=Sleep)58internalexternstatic

7、voidSleep(intdwMilliseconds);5960/得到鼠标相对与全屏的坐标,不是相对与你的Form的,且与你的分辨率有关系6162publicstaticintFullScreenPosition_X6364get6566POINTAPI_POINTAPI=newPOINTAPI();6768GetCursorPos(ref_POINTAPI);6970return_POINTAPI.x;71727374publicstaticintFullScreenPosition_Y7576get7778POINTAPI_POINTAPI=newPOINTAPI();7980GetCu

8、rsorPos(ref_POINTAPI);8182return_POINTAPI.y;83848586/隐藏显示鼠标87publicstaticvoidHide()8889ShowCursor(false);909192publicstaticvoidShow()9394ShowCursor(true);959697/将鼠标锁定在你的Form里不过你得将你的Form先锁了,FormResize就失效了98publicstaticvoidLock(System.Windows.Forms.FormObjectForm)99100RECT_FormRect=newRECT();101102Get

9、WindowRect(ObjectForm.Handle.ToInt32(),ref_FormRect);103104ClipCursor(ref_FormRect);105106107publicstaticvoidUnLock()108109RECT_ScreenRect=newRECT();110111_ScreenRect.top=0;112_ScreenRect.left=0;113_ScreenRect.bottom=System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Bottom;114_ScreenRect.right=S

10、ystem.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Right;115116ClipCursor(ref_ScreenRect);117118119/鼠标失效,不过失效的好像不只是鼠标,小心哦120publicstaticvoidDisable(System.Windows.Forms.FormObjectForm)121122EnableWindow(ObjectForm.Handle.ToInt32(),0);123124125publicstaticvoidEnable(System.Windows.Forms.FormObjectF

11、orm)126127EnableWindow(ObjectForm.Handle.ToInt32(),1);128129/得到你的鼠标类型130publicstaticstringType131132get133134if(GetSystemMetrics(SM_MOUSEPRESENT)=0)135136return本计算机尚未安装鼠标;137138else139140if(GetSystemMetrics(SM_MOUSEWHEELPRESENT)!=0)141142returnGetSystemMetrics(SM_CMOUSEBUTTONS)+键滚轮鼠标;143144else14514

12、6returnGetSystemMetrics(SM_CMOUSEBUTTONS)+键鼠标;147148149150151152/设置鼠标双击时间153publicstaticvoidDoubleClickTime_Set(intMouseDoubleClickTime)154155SetDoubleClickTime(MouseDoubleClickTime);156157158publicstaticstringDoubleClickTime_Get()159160returnGetDoubleClickTime().ToString();161162163/设置鼠标默认主键164publ

13、icstaticvoidDefaultRightButton()165166SwapMouseButton(1);167168169publicstaticvoidDefaultLeftButton()170171SwapMouseButton(0);172173调用如下:1/锁窗体2Mouse.Lock(this);3/锁光标4Mouse.Disable(this);12) . 标 ( 体/ ; 0 标. 体 ) 个 鼠 认标标/ ) * ) / / ) ( (_ 击鼠 ;键) _( 滚) (0 ;鼠尚本 )=) ( 标你 ) . ) 0) . ) . ( 0哦,是像失过标/ _ ( . . _ ; . . 0 0= _ ( _ 0 0 ( 0 , . 00( = 0) . 效就 了 得不 的在鼠/ ; ) ) 示藏/ ) _ ) = 率辨与的 你是标屏与鼠/ ( = , ( . ) , . . . , ( . ) . . ; ) . ( . . , ( = . ( . . ( = ( = ;) ( = . 0 ; ) = ( ; = ; ; / - / /

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 教育专区 > 高考资料

本站为文档C TO C交易模式,本站只提供存储空间、用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。本站仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知淘文阁网,我们立即给予删除!客服QQ:136780468 微信:18945177775 电话:18904686070

工信部备案号:黑ICP备15003705号© 2020-2023 www.taowenge.com 淘文阁