试图做的是,在目前形式的某种位置上取得一种颜色。 但是,我称之为这一方法的时机已经成熟。 当我提出申请时,我有了一个错误:
Cross-thread operation not valid: Control Form1 accessed from a thread other than the thread it was created on.
阅读法:
Thread drawThread;
drawThread = new Thread(drawBikes);
《刑法》:
public void drawBikes()
{
MessageBox.Show("Bike "+bike.color.ToString()+": "+Form1.ActiveForm.GetPixelColor(bike.location.X, bike.location.Y).ToString());
}
这里是“GetPixelColor”方法(在一个单独的固定类别中):
public static class ControlExts
{
public static Color GetPixelColor(this Control c, int x, int y)
{
var screenCoords = c.PointToScreen(new Point(x, y));
return Win32.GetPixelColor(screenCoords.X, screenCoords.Y);
}
}
我在什么地方叫Invoke?