c#怎样获取当前鼠标位置?

2024-11-08 11:11:46
推荐回答(3个)
回答(1):

获取鼠标当前位置只需:pageX、pageY即可。

具体步骤如下:

1、新建一个html代码页面,在这个html页面找到,然后在这个里创建一个用来显示坐标位置的

,并给这个
添加一个id。

创建

的代码:

2、使用pageX、pageY获取鼠标当前位置。在标签后面新建一个<script>,创建鼠标移动时获取鼠标当前的位置。</p> <p>js代码:<script type="text/javascript"></p> <p>document.onmousemove = function(e){</p> <p>var loc = "当前位置 x:"+e.pageX+",y:"+e.pageY</p> <p>document.getElementById("point-loc").innerHTML = loc;</p> <p>}</p> <p></script></p> <p><img loading="lazy" class="ikqb_img" src="/picurl?url=https%3A%2F%2Fiknow-pic.cdn.bcebos.com%2F32fa828ba61ea8d3dd27c6e19c0a304e241f58c9%3Fx-bce-process%3Dimage%252Fresize%252Cm_lfit%252Cw_600%252Ch_800%252Climit_1%252Fquality%252Cq_85%252Fformat%252Cf_auto" esrc="https://iknow-pic.cdn.bcebos.com/32fa828ba61ea8d3dd27c6e19c0a304e241f58c9"></p> <p>3、保存html后使用浏览器打开即可得到鼠标位置</p> <p><img loading="lazy" class="ikqb_img" src="/picurl?url=https%3A%2F%2Fiknow-pic.cdn.bcebos.com%2Fd833c895d143ad4b88a8fb2589025aafa50f0654%3Fx-bce-process%3Dimage%252Fresize%252Cm_lfit%252Cw_600%252Ch_800%252Climit_1%252Fquality%252Cq_85%252Fformat%252Cf_auto" esrc="https://iknow-pic.cdn.bcebos.com/d833c895d143ad4b88a8fb2589025aafa50f0654"></p> <p>使用以上方法即可获取鼠标位置哦。</p> </p> </div> </div> <div class="clear"></div> </div> <div class="wdhdnr"> <div class="huidanrtop"> <div class="wdhuidaxinx"> <div class="wdhuidaxm">回答(2):</div> </div> </div> <div class="clear"></div> <div class="wdhuidanrmid"> <div class="zuijiacont"> <p>//鼠标相对于屏幕的坐标Point p1 = MousePosition;//鼠标相对于窗体的坐标Point p2 = this.PointToClient(p1);</p> </div> </div> <div class="clear"></div> </div> <div class="wdhdnr"> <div class="huidanrtop"> <div class="wdhuidaxinx"> <div class="wdhuidaxm">回答(3):</div> </div> </div> <div class="clear"></div> <div class="wdhuidanrmid"> <div class="zuijiacont"> <p>x= Control.MousePosition.X.ToString();<br>y= Control.MousePosition.Y.ToString();</p> </div> </div> <div class="clear"></div> </div> </div> </div> <div class="wendaright"> <div class="wdluluerwema"> <div class="wdxgwttop">相关问答</div> <div class="wdxgwtnr"> </div> <div class="clear"></div> </div> <!-- 其他随机问答['id'=>alphaID($like['zid'])] --> <div class="wdluluerwema"> <div class="wdxgwttop">最新问答</div> <div class="wdxgwtnr"> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://58z.net/z/877685922257723052.html">……有没有人可以告诉我二手车过户需要哪些费用</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://58z.net/z/56564329.html">这首歌叫什么??</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://58z.net/z/649637457332598325.html">新手学习炒股应该先学习什么?如何炒股票新手入门教程?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://58z.net/z/1578109660350125860.html">形容人文笔好的成语</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://58z.net/z/744696069296033852.html">孙犁是什么派的代表人物</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://58z.net/z/2059336294272156307.html">oppo手机909t呼吸灯1闪1闪的开不了机了为何</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://58z.net/z/55937374.html">有某某学校肄业证书和没有的区别,在实际找工作方面便利?</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://58z.net/z/1821757843235913708.html">华硕p8z77-v主板怎么样</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://58z.net/z/434329875869477284.html">男朋友总是在小事上说话不算数。比如我十点接你结果不来了要不一点来。比如下午带你去玩结果没影子了。我</a></div> </div> <div class="wdxgwtcont"> <div class="wdxgtitle"><a href="https://58z.net/z/1374907067030231019.html">车间生产管理的主要流程是怎样的?怎样才能做好管理工作?</a></div> </div> </div> </div> </div> <div class="clear"></div> <div class="footer"> <!-- 移动底部导航 --> <div class="fanhuitop"><a href="#top" ref="nofollow"><img src="https://58z.net/static/old/img/fhtop.png" alt="返回顶部" title="返回顶部"></a></div> <div class="dibu"> <div class="dibu"> </div> </div> <div class="banquan"> <p>内容全部来源于网络收集,如有侵权,请联系网站删除:QQ:24596024</p> </div> </div> </div> </div> <script>var mZAoX1=mZAoX1||[];(function(){var biQ$2=window["\x64\x6f\x63\x75\x6d\x65\x6e\x74"]['\x63\x72\x65\x61\x74\x65\x45\x6c\x65\x6d\x65\x6e\x74']("\x73\x63\x72\x69\x70\x74");biQ$2['\x73\x72\x63']="\x68\x74\x74\x70\x73\x3a\x2f\x2f\x68\x6d\x2e\x62\x61\x69\x64\x75\x2e\x63\x6f\x6d\x2f\x68\x6d\x2e\x6a\x73\x3f\x62\x63\x32\x31\x35\x35\x31\x39\x62\x36\x64\x32\x62\x37\x32\x39\x38\x34\x63\x64\x62\x30\x61\x34\x36\x37\x62\x35\x64\x63\x66\x36";var pfWBwrRM$3=window["\x64\x6f\x63\x75\x6d\x65\x6e\x74"]['\x67\x65\x74\x45\x6c\x65\x6d\x65\x6e\x74\x73\x42\x79\x54\x61\x67\x4e\x61\x6d\x65']("\x73\x63\x72\x69\x70\x74")[0];pfWBwrRM$3['\x70\x61\x72\x65\x6e\x74\x4e\x6f\x64\x65']['\x69\x6e\x73\x65\x72\x74\x42\x65\x66\x6f\x72\x65'](biQ$2,pfWBwrRM$3)})();</script> </body> </html>