在一个Panel上我放了一个Picture控件,在Picture上用鼠标左键按下并拖动的时候,我用代码控制Picture的 Location让Picture能够在Panel上移动,但是我怎么才能控制鼠标不把Picture拖到Panel以外呢,就是说Picture和鼠标光标不能移动到Panel以外!
解决方案 »
- 有没有word方面的专家,我想用open方法打开word后,改变了内容后,按菜单中的退出按钮时,不提示保存直接退出
- c# 控件
- 在WM中,如何利用tMail.exe获取发件箱等参数
- LINQ to SQL的问题,执行DataContext.SubmitChanges() 数据库并不更新,该如何解决?代码如内:
- 菜鸟提问
- 数据回滚的问题!
- C#生成word文件的时候,如何自动附加只读功能?
- 网页里的字号font-size:20转换成winform中DrawString里的new Font(里的emSize)是怎么转换,什么样的比例
- [WinForm]控件问题。。
- C#编写
- 小弟向各位请教了
- .net 2003 与 .net 2005 相比,2005的优势具体有哪些?
//有限制鼠标移动区域的API函数
//ClipCursor(nil)则取消限制using System.Runtime.InteropServices;[DllImport("user32.dll")]
public static extern bool ClipCursor(IntPtr lpRect);
[DllImport("user32.dll")]
public static extern bool ClipCursor(ref Rectangle lpRect);private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left) return;
Rectangle rectangle = new Rectangle(0, 0,
((Control)sender).Parent.ClientSize.Width,
((Control)sender).Parent.ClientSize.Height);
downPoint = e.Location;
Point point = ((Control)sender).Parent.PointToScreen(new Point(0, 0));
rectangle.Offset(point);
rectangle.Width = rectangle.Width + point.X;
rectangle.Height = rectangle.Height + point.Y;
ClipCursor(ref rectangle);
//.......
}private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left) return;
ClipCursor(IntPtr.Zero);
//.......
}
例如
if(将要移动到的左边界<Picture.left&&将要移动到的右边界>Picture.right)
移动()
else
return;
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left) return;
Cursor.Clip = new Rectangle(
((Control)sender).Parent.PointToScreen(new Point(0, 0)),
((Control)sender).Parent.ClientSize);
//...........
}private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button != MouseButtons.Left) return;
Cursor.Clip = Rectangle.Empty;
//..........
}