using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication2
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.ComponentModel.IContainer components;
private Rectangle oldRect;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
Console.WriteLine(this.panel1.Location); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.Red;
this.panel1.Location = new System.Drawing.Point(104, 56);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(208, 184);
this.panel1.TabIndex = 0;
this.panel1.MouseEnter += new System.EventHandler(this.OnMouseEnter);
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(168, 40);
this.label1.TabIndex = 1;
this.label1.Text = "注意!您的鼠标进入红色区域后,将被锁定在此区域内,按Ctrl + L解锁.";
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.Shortcut = System.Windows.Forms.Shortcut.CtrlL;
this.menuItem1.Text = "UnLock";
this.menuItem1.Visible = false;
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(448, 309);
this.Controls.Add(this.label1);
this.Controls.Add(this.panel1);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void OnMouseEnter(object sender, System.EventArgs e)
{
Rectangle r = new Rectangle(this.panel1.Location,this.panel1.Size);
r.X += this.Location.X;
r.Y += this.Location.Y + SystemInformation.CaptionHeight;
oldRect = Cursor.Clip;
Cursor.Clip = r;
} private void menuItem1_Click(object sender, System.EventArgs e)
{
Console.WriteLine(oldRect);
Cursor.Clip = SystemInformation.WorkingArea;
this.Activate();
}
}
}
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication2
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.ComponentModel.IContainer components;
private Rectangle oldRect;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
Console.WriteLine(this.panel1.Location); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.panel1 = new System.Windows.Forms.Panel();
this.label1 = new System.Windows.Forms.Label();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.SuspendLayout();
//
// panel1
//
this.panel1.BackColor = System.Drawing.Color.Red;
this.panel1.Location = new System.Drawing.Point(104, 56);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(208, 184);
this.panel1.TabIndex = 0;
this.panel1.MouseEnter += new System.EventHandler(this.OnMouseEnter);
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 8);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(168, 40);
this.label1.TabIndex = 1;
this.label1.Text = "注意!您的鼠标进入红色区域后,将被锁定在此区域内,按Ctrl + L解锁.";
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.Shortcut = System.Windows.Forms.Shortcut.CtrlL;
this.menuItem1.Text = "UnLock";
this.menuItem1.Visible = false;
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(448, 309);
this.Controls.Add(this.label1);
this.Controls.Add(this.panel1);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void OnMouseEnter(object sender, System.EventArgs e)
{
Rectangle r = new Rectangle(this.panel1.Location,this.panel1.Size);
r.X += this.Location.X;
r.Y += this.Location.Y + SystemInformation.CaptionHeight;
oldRect = Cursor.Clip;
Cursor.Clip = r;
} private void menuItem1_Click(object sender, System.EventArgs e)
{
Console.WriteLine(oldRect);
Cursor.Clip = SystemInformation.WorkingArea;
this.Activate();
}
}
}
解决方案 »
- 如何设置键盘,使得某个键显示另一个一个特定的功能,例如,按下A键显示B字符
- .NET导入C++的Dll文件
- 程序集注册工具 Regasm.exe这东东砸用?
- 新手问题 有关于数据库的!
- C#中多窗体程序设计问题
- 请问一下,有没有什么办法把EXCEL表格嵌入到WinForm中,然后进行操作啊?
- 怎么给DropDownList直接付值
- 已经知道行号和列号,如何修改dataset里的值?
- 请教:设定DataGrid的Cell的高度后,如何使显示的文字纵向居中显示。
- 有一个数据源,它有很多字段,绑定到DataGrid后,如何让它只显示我要的几个字段呢
- 在ListBox中双击一个选项,该响应什么事件?
- c#中能不能忽略大小写???
public struct RECT
{
public int left;
public int top;
public int right;
public int bottom;
}
[System.Runtime.InteropServices.DllImport("user32" , EntryPoint="ClipCursor")]
public static extern int ClipCursor(ref RECT lpRect); 用以上函数即可锁定在一个区域。
public static extern int ClipCursor (
ref int lpRect
);