我创建了一个新控件并覆盖了 OnPaint 事件:
protected override void OnPaint(PaintEventArgs e)
{
Graphics g = e.Graphics;
_ammo = PitControl.Ammo;
var AmmoSize = g.MeasureString(_ammo.ToString(), Properties.Settings.Default.AmmoFont).ToSize();
g.DrawString(_ammo.ToString(), Properties.Settings.Default.AmmoFont, Brushes.WhiteSmoke, Ammo.Location.X - 1, Ammo.Location.Y + Ammo.Height / 2 - AmmoSize.Height / 2 + 1);
Rectangle DrawAmmo = new Rectangle(this.Width - Ammo.Height - _margin, Ammo.Location.Y, Ammo.Height, Ammo.Height);
for (int i = _ammo; i > 0; i--)
if (i % 2 == 0)
g.DrawLine(_ammoPen, Ammo.Location.X + Ammo.Width - i - 1, Ammo.Location.Y + 3, Ammo.Location.X + Ammo.Width - i - 1, Ammo.Location.Y + Ammo.Height - 3);
g.DrawRectangle(Pens.Orange, Ammo);
g.DrawImage(Properties.Resources.ammunition, DrawAmmo.Location.X, DrawAmmo.Location.Y, DrawAmmo.Height, DrawAmmo.Height);
}
问题是当我改变弹药然后所有的控制轻弹。
看起来不太好。
无论如何,让我在这条线上画的线:
g.DrawLine(_ammoPen, Ammo.Location.X + Ammo.Width - i - 1, Ammo.Location.Y + 3, Ammo.Location.X + Ammo.Width - i - 1, Ammo.Location.Y + Ammo.Height - 3);
只是在弹药变化时消失?