如题。 有其他方法解决也可以。
本人用过下面方法
[DllImport("user32.dll", EntryPoint="ShowCursor", CharSet=CharSet.Auto)]
public static extern int ShowCursor(int bShow);
ShowCursor(1)
但只能隐藏当前程序界面中的鼠标。 我要求全部隐藏,在其他进程中也不可见。

解决方案 »

  1.   

    to 如果在C#中调用API函数,使鼠标隐藏或限制在一定区域???其实你可以在本窗体中隐藏了cursor,
    然后调用SetCapture把鼠标限制在本窗体内,关闭窗体的时候再调用ReleaseCapture来释放。SetCapture:
    http://www.pinvoke.net/default.aspx/user32/SetCapture.htmlReleaseCapture:
    http://www.pinvoke.net/default.aspx/user32/ReleaseCapture.html
      

  2.   

    感谢 Knight94(愚翁) 提供的方法,但我以前没做过类似的东西,还请你详细讲解一下,多谢!!!我新建了一个类 WinAPI.cs 在其中写了
    [DllImport("user32.dll")]
    public static extern IntPtr SetCapture(IntPtr hWnd);
    public static extern bool ReleaseCapture();
    //public static extern int ShowCursor(int bShow);//隐藏鼠标在前台该如何调用?
      

  3.   

    ReleaseCapture应该如下:
    [DllImport("user32")]
    public static extern int ReleaseCapture(IntPtr hwnd);调用
    SetCapture( this.Handle );//Set capture
    ReleaseCapture( this.Handle );//Release capture
      

  4.   

    而且运行时出现错误提示,调用方法 ReleaseCapture 没有RVA。
      

  5.   

    操作系统2003server 开发工具vs2005 c#
    类文件代码
    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。
      

  6.   

    这是调试用的一个小程序, 我所做的程序引用了第三方控件sandbar.dll
    会出现
    “未处理的“System.TypeLoadException”类型的异常出现在 sandbar.dll 中。”
    我的QQ30724229。希望通过QQ交流。谢谢!!
      

  7.   

    定义区域:
    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;