當我的代碼只運行約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();
或者讓它在'default'上打印一些警告信息。一條線不能傳遞儘可能多的信息,並可能融入到應用程序中。 –
NoOfGuesses始終在此範圍內。此外,如果是這樣的錯誤,那麼它不會在某些時候畫出線條,而不會畫出線條。 – user1763295