当前位置:编程学习 > C#/ASP.NET >>

C#中怎么样将鼠标锁定在某个特定的form上?

只能在上面移动,而不能移到外面去? --------------------编程问答-------------------- 把你的form大小设定的跟桌面一样大鼠标就出不去了
现在的多任务操作系统想这么做不太好办 --------------------编程问答-------------------- Cursor.Clip试试

--------------------编程问答--------------------
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);
        }
    }
}
--------------------编程问答-------------------- 学习楼上。 --------------------编程问答-------------------- 三楼的代码能否保证在按Ctrl+Alt+Del的时候也有效?

或者按Alt+Tab的时候 --------------------编程问答-------------------- 呵,要保证按快捷键也有效那好象要用键盘钩子了吧
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,