当我的代码只运行大约 1/3 的时间时,它实际上会正确绘制,其余的则不会绘制一些线条。
Pen pen = new Pen(Color.Black);
Graphics graphics = MainFrm.HangmanImage.CreateGraphics();
switch (NoOfGuesses)
{
case 1://Bottom left leg
graphics.DrawLine(pen, 15, 60, 40, 60);
break;
case 2://Bottom right leg
graphics.DrawLine(pen, 40, 60, 55, 60);
break;
case 3://Middle stock
graphics.DrawLine(pen, 34, 20, 34, 60);
break;
case 4: //Top line
graphics.DrawLine(pen, 34, 20, 55, 20);
break;
case 5: //Rope
graphics.DrawLine(pen, 55, 20, 55, 25);
break;
case 6: //Head
graphics.DrawEllipse(pen, (new Rectangle { X=52, Y=25, Height=5, Width=5 }));
break;
case 7: //Body
graphics.DrawLine(pen, 55, 30, 55, 35);
break;
}
pen.Dispose();
graphics.Dispose();