这个问题比较难解决,你可定义1个类:
public class RectangleCollection : System.Collections.CollectionBase {} 在窗体里面加入 RectangleCollection sharp = new SharpRectCollection();
从数据库里加载一条数据 sharp.Add(new Rectangle(location, size);
绘制的时候:foreach(Rectangle rect in this.sharp)
{
if(rect.contains(p)) this.picturebox.cursor = Cursors.upArrow;
else this.picturebox.cursor = Cursors.default;
}在 PictureBox 的 MouseMove 事件里判断:Point p = new Point(e.x,e.y);foreach(Rectangle rect in this.sharp)
{
e.Graphics.DrawRectangle(...)
}
public class RectangleCollection : System.Collections.CollectionBase {} 在窗体里面加入 RectangleCollection sharp = new SharpRectCollection();
从数据库里加载一条数据 sharp.Add(new Rectangle(location, size);
绘制的时候:foreach(Rectangle rect in this.sharp)
{
if(rect.contains(p)) this.picturebox.cursor = Cursors.upArrow;
else this.picturebox.cursor = Cursors.default;
}在 PictureBox 的 MouseMove 事件里判断:Point p = new Point(e.x,e.y);foreach(Rectangle rect in this.sharp)
{
e.Graphics.DrawRectangle(...)
}
public class RectangleCollection : System.Collections.CollectionBase {} 在窗体里面加入 RectangleCollection sharp = new SharpRectCollection();
从数据库里加载一条数据 sharp.Add(new Rectangle(location, size);
绘制的时候:foreach(Rectangle rect in this.sharp)
{
e.Graphics.DrawRectangle(...)
}
在 PictureBox 的 MouseMove 事件里判断:Point p = new Point(e.x,e.y);foreach(Rectangle rect in this.sharp)
{
if(rect.contains(p)) this.picturebox.cursor = Cursors.upArrow;
else this.picturebox.cursor = Cursors.default;
}
代码如下,我用一个对象数组来实现的!
for(int i = 0; i<count;i++)
{
if(rect[i].Contains(p))
{
this.pictureBox1.Cursor = Cursors.UpArrow;
//return语句不可少
return;
}
else
this.pictureBox1.Cursor = Cursors.Default;
}
其中关键是return 语句,如果没有,只能显示最后一个,谢谢楼上那位,你的思想和我的思想一样!
for(int i = 0; i<count;i++)
{
if(rect[i].Contains(p))
{
this.pictureBox1.Cursor = Cursors.UpArrow;
this.textbox.top = rect[i].y +20;
this.textbox.left = rect[i].x;
this.tectbox.visible = true;
//return语句不可少
return;
}
else
{
this.pictureBox1.Cursor = Cursors.Default;
this.textbox.visible = false;
}
加入这些语句之后,鼠标在矩形里在upArrow和default之间来回变动,不知道是怎么回事?请高手指教!!!在线急等!!!!
}