这是我的代码,
private bool isMouseOverPin(int x, int y, Pin pin)
{
int left, top, right, bottom,size;
size=5;
left = pin.theRectangle.Left-size;
right = pin.theRectangle.Right + size;
top = pin.theRectangle.Top - size;
bottom = pin.theRectangle.Bottom + size;
if (x >= left && y >= top && x <= right && y <= bottom)
{
return true;
}
else
{
return false;
}
}
private void pinHover()
{
for (int i = 0; i < pins.Count; i++)
{
if (isMouseOverPin(Cursor.Position.X, Cursor.Position.Y, pins[i]) == true)
{
using (Graphics gr=canvas.CreateGraphics())
{
gr.DrawRectangle(10,10,10,10);
}
}
}
}
private void canvas_MouseMove(object sender, MouseEventArgs e)
{
pinHover();
}
我想当有人将鼠标放在一个大头针上时,它会绘制一个矩形,大头针大小为 5,我无法理解为什么它不能正常工作。帮助请