如题。 有其他方法解决也可以。
本人用过下面方法
[DllImport("user32.dll", EntryPoint="ShowCursor", CharSet=CharSet.Auto)]
public static extern int ShowCursor(int bShow);
ShowCursor(1)
但只能隐藏当前程序界面中的鼠标。 我要求全部隐藏,在其他进程中也不可见。
本人用过下面方法
[DllImport("user32.dll", EntryPoint="ShowCursor", CharSet=CharSet.Auto)]
public static extern int ShowCursor(int bShow);
ShowCursor(1)
但只能隐藏当前程序界面中的鼠标。 我要求全部隐藏,在其他进程中也不可见。
解决方案 »
- 有关C#与JAVA通过JOSN通信问题
- C#怎么往Dataset里面加载多张表?
- 怎么在程序中测试中向Imagelist添加图片,并且再下次测试的时候能够看到新添加的图片!
- 请前辈讲解一下C#里的一两个基本概念.
- 求牛人看看这样的线程怎么同步呀(Socket的SocketAsyncEventArgs异步发送)
- 如何向oracle插入空字符
- 100请教,类似于用友的带下划线的文本录入框
- 有关网页数据采集的几个问题(200分相送)
- 请各们大虾帮忙,关于.net显示中文的,谢谢!
- vs2015打开某个解决方案特别慢
- 我想在.net2003下做个自定义控件,但提示错误:找不到文件或程序集"Class1",或其依赖项
- 如何根据DataSet中自已构建的DataTable在数据库中创建表格
然后调用SetCapture把鼠标限制在本窗体内,关闭窗体的时候再调用ReleaseCapture来释放。SetCapture:
http://www.pinvoke.net/default.aspx/user32/SetCapture.htmlReleaseCapture:
http://www.pinvoke.net/default.aspx/user32/ReleaseCapture.html
[DllImport("user32.dll")]
public static extern IntPtr SetCapture(IntPtr hWnd);
public static extern bool ReleaseCapture();
//public static extern int ShowCursor(int bShow);//隐藏鼠标在前台该如何调用?
[DllImport("user32")]
public static extern int ReleaseCapture(IntPtr hwnd);调用
SetCapture( this.Handle );//Set capture
ReleaseCapture( this.Handle );//Release capture
类文件代码
using System;
using System.Runtime.InteropServices;
namespace WindowsApplication3
{
/// <summary>
/// winapi 的摘要说明。
/// </summary>
/// [DllImport("user32.dll")]
public class winapi
{
[DllImport("user32.dll")]
public static extern IntPtr SetCapture(IntPtr hWnd);
public static extern int ReleaseCapture(IntPtr hwnd); public winapi()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
}
}
前台调用代码 private void button1_Click(object sender, System.EventArgs e)
{
winapi.SetCapture(this.Handle);
} private void button2_Click(object sender, System.EventArgs e)
{
winapi.ReleaseCapture(this.Handle );
}
出现错误:button1点击事件未处理的“System.TypeLoadException”类型的异常出现在 system.windows.forms.dll 中。其他信息: 未能从加载程序集 WindowsApplication3, Version=1.0.2434.17534, Culture=neutral, PublicKeyToken=null 中加载类型 WindowsApplication3.winapi,因为方法 ReleaseCapture 没有 RVA。
会出现
“未处理的“System.TypeLoadException”类型的异常出现在 sandbar.dll 中。”
我的QQ30724229。希望通过QQ交流。谢谢!!
System.Drawing.Rectangle r = new System.Drawing.Rectangle(0 ,0 , 50 , 50 );
System.Windows.Forms.Cursor.Clip = r; 释放:
System.Drawing.Rectangle r1 = new System.Drawing.Rectangle(0 ,0 ,this.Width ,this.Height );
System.Windows.Forms.Cursor.Clip = r1;