把你的form大小设定的跟桌面一样大鼠标就出不去了
现在的多任务操作系统想这么做不太好办

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Runtime.InteropServices;
    namespace WindowsApplication12
    {
        public partial class Form1 : Form
        {
            [DllImport("User32.dll")]
            public static extern int ClipCursor(ref Rect r);
            public Form1()
            {
                InitializeComponent();
            }
            [StructLayout(LayoutKind.Explicit)]
            public struct Rect
            {
                [FieldOffset(0)]
                public int left;
                [FieldOffset(4)]
                public int top;
                [FieldOffset(8)]
                public int right;
                [FieldOffset(12)]
                public int bottom;
            }        private void Form1_Load(object sender, EventArgs e)
            {        }        private void Form1_MouseMove(object sender, MouseEventArgs e)
            {
                Rect a;
                Rectangle r = this.ClientRectangle;
                r.Offset(this.Location);
                a.top = r.Top;
                a.right = r.Right;
                a.bottom = r.Bottom;
                a.left = r.Left;
                ClipCursor(ref a);
            }
        }
    }
      

  2.   

    三楼的代码能否保证在按Ctrl+Alt+Del的时候也有效?或者按Alt+Tab的时候