I create a new Control and overided the OnPaint event:
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);
}
The problem is when i'm changing the Ammo then all the control flicks.
It doesn't look good.
Anyway to make the lines that i draw on this line:
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);
Just disapeare when ammo is changing ?