using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Threading; namespace TradeIdeas.TIProGUI.RealTimeStockRace { public partial class RaceStartControl : UserControl { private const float RACE_START_SECONDS = 30; private int _seconds; public RaceStartControl() { InitializeComponent(); } public void SetSeconds(int seconds) { this.InvokeIfRequired(delegate { _seconds = seconds; lblCountDown.Text = seconds.ToString(); this.Invalidate(); }); } private void RaceStartControl_Resize(object sender, EventArgs e) { lblCountDown.Left = (this.Width - lblCountDown.Width) / 2; lblCountDown.Top = (this.Height - lblCountDown.Height) / 2; } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); // Draw circle around seconds. using (Pen pen = new Pen(Color.White) { Width = 5 }) { //e.Graphics.DrawEllipse(pen, ClientRectangle); e.Graphics.DrawEllipse(pen, this.Width / 2 - 50, this.Height / 2 - 50, 100, 100); } // Draw arc around seconds. using (Pen pen = new Pen(Color.Black) { Width = 5 }) { //e.Graphics.DrawEllipse(pen, ClientRectangle); e.Graphics.DrawArc(pen, this.Width / 2 - 50, this.Height / 2 - 50, 100, 100, 0F, 360F * ((float)_seconds / RACE_START_SECONDS)); } } } }