有时,如果我按住左箭头键,pictureBox 将停止绘制我的角色的坐标。一个典型的例子是红圈中的黄点。通过按住左箭头键,pictureBox 并没有不断地绘制我的角色位置,直到我按下另一个键/放开箭头键,然后picturebox 再次开始更新(如您所见以紫色包围)。
此外,我遇到的另一个错误是它应该只在每个位置绘制一个黄点和一个“蓝色漩涡”;虽然它正在绘制多个(如您所见)。
下面的代码是我用来复制图片结果的代码。
private Thread grabValues;
private Bitmap bm;
private Image image1;
private Image image2;
private Graphics gM;
void RGraphics()
{
image1 = Properties.Resources.image1;
image2 = Properties.Resources.image2;
}
void RInvokeMe()
{
while (true)
{
if (this.InvokeRequired)
{
this.Invoke(new UpdateControlsDelegate(MUpdate));
this.Invoke(new UpdateControlsDelegate(CUpdate));
}
else
{
MUpdate();
CUpdate();
}
}
}
void MUpdate()
{
pictureBox1.ImageLocation = "http://urlexample/r/we.png";
}
void CUpdate()
{
bm = new Bitmap(pictureBox1.Image);
gM = Graphics.FromImage(bm);
gM.CompositingMode = CompositingMode.SourceOver;
MDraw.DrawBlueDot(gM, image2, X2, Y2);
MDraw.DrawYellowDot(gM, image1, X1, Y1);
pictureBox1.Image = bm;
pictureBox1.Refresh();
}
public Form2()
{
InitializeComponent();
RGraphics();
grabValues = new Thread(new ThreadStart(RInvokeMe));
grabValues.IsBackground = true;
grabValues.Start();
}