using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace TIProSkunkWorksExtension { public partial class RealTimeStockRaceControl: UserControl { int _laneNumber = 0; private PictureBox _flagPictureBox; //private bool _showRaceCountdown = false; // Take out countdown seconds - RVH20220309 //private int _seconds; // Take out countdown seconds - RVH20220309 private const float RACE_START_SECONDS = 30; private enum RaceLightStatus { Green, Yellow, Red }; private RaceLightStatus _raceLightStatus = RaceLightStatus.Red; //private RaceStartControl _raceStartControl; //RaceLaneControl _raceLaneControl; public RealTimeStockRaceControl() { InitializeComponent(); } public void ResetLaneNumber() { _laneNumber = 0; } public RaceLaneControl AddRaceLane(int top, string symbol, double startBasedOn, string basedOnCode, string units, bool showComplimentUnits, Color symbolTextColor, int symbolWidth, double? startBasedOnCompliment = null, string basedOnComplimentCode = null, bool biggestLoserWins = false) { // Add a race car control _laneNumber++; RaceCarControl raceCarControl = new RaceCarControl(symbol, _laneNumber, symbolTextColor, symbolWidth) { Top = 2, Left = 0 }; // Add a race lane control RaceLaneControl raceLaneControl = new RaceLaneControl(raceCarControl, symbol, startBasedOn, basedOnCode, units, showComplimentUnits, startBasedOnCompliment, basedOnComplimentCode, biggestLoserWins) { Top = top, Left = 0, Width = this.Width, Anchor = AnchorStyles.Left | AnchorStyles.Right }; this.Controls.Add(raceLaneControl); return raceLaneControl; } public void RemoveAllRaceCarLanes() { List controlsToRemove = new List(); foreach (Control control in Controls) { RaceLaneControl raceLaneControl = control as RaceLaneControl; if (raceLaneControl != null) controlsToRemove.Add(raceLaneControl); } foreach (Control control in controlsToRemove) { Controls.Remove(control); control.Dispose(); } } private void ResizeAllRaceCarLanes() { int lanePosition = 0; foreach (Control control in Controls) { RaceLaneControl raceLaneControl = control as RaceLaneControl; if (raceLaneControl != null) { raceLaneControl.Top = lanePosition; raceLaneControl.Width = this.Width; raceLaneControl.Invalidate(); lanePosition += 30; } } } public void ShowFinishFlag() { _flagPictureBox = new PictureBox() { Image = Properties.Resources.race_flag_10, SizeMode = PictureBoxSizeMode.StretchImage, Size = this.Size, Location = new Point(0, 0), BackColor = Color.Transparent }; this.Controls.Add(_flagPictureBox); _flagPictureBox.BringToFront(); } public void HideFinishFlag() { this.Controls.Remove(_flagPictureBox); _flagPictureBox.Dispose(); } public void ShowRaceStart() { // Take out countdown seconds - RVH20220309 //_showRaceCountdown = true; picRaceLights.Visible = true; UpdateRaceStart(true); // Take out countdown seconds - RVH20220309 //lblCountDown.Visible = true; } public void UpdateRaceStart(bool reset) { if (reset) { // Reset status to red light. _raceLightStatus = RaceLightStatus.Red; } else { // Update status to next light. if (_raceLightStatus == RaceLightStatus.Red) { // Set status to yello light. _raceLightStatus = RaceLightStatus.Yellow; } else if (_raceLightStatus == RaceLightStatus.Yellow) { // Set status to green light. _raceLightStatus = RaceLightStatus.Green; } } // Update race light image. switch (_raceLightStatus) { case RaceLightStatus.Green: picRaceLights.Image = Properties.Resources.racelights_green; break; case RaceLightStatus.Yellow: picRaceLights.Image = Properties.Resources.racelights_yellow; break; case RaceLightStatus.Red: picRaceLights.Image = Properties.Resources.racelights_red; break; } } // Take out countdown seconds - RVH20220309 //public void ShowRaceStartSeconds(int seconds) //{ // _seconds = seconds; // lblCountDown.Text = seconds.ToString(); // this.Invalidate(); // this.Update(); //} public void HideRaceStart() { // Take out countdown seconds - RVH20220309 //_showRaceCountdown = false; picRaceLights.Visible = false; // Take out countdown seconds - RVH20220309 //lblCountDown.Visible = false; //this.Invalidate(); //this.Update(); } protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); // Draw lines on race lane. using (Pen pen = new Pen(Color.White) { Width = 2 }) { e.Graphics.DrawLine(pen, Convert.ToSingle(this.Width * 0.25), 0, Convert.ToSingle(this.Width * 0.25), this.Height); e.Graphics.DrawLine(pen, Convert.ToSingle(this.Width * 0.50), 0, Convert.ToSingle(this.Width * 0.50), this.Height); e.Graphics.DrawLine(pen, Convert.ToSingle(this.Width * 0.75), 0, Convert.ToSingle(this.Width * 0.75), this.Height); } // Take out countdown seconds - RVH20220309 //if (_showRaceCountdown) //{ // // Draw circle around seconds. // using (Pen pen = new Pen(Color.White) // { // Width = 3 // }) // { // //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 = 3 // }) // { // //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)); // } //} } private void RealTimeStockRaceControl_Resize(object sender, EventArgs e) { picRaceLights.Left = (this.Width - picRaceLights.Width) / 2; picRaceLights.Top = (this.Height - picRaceLights.Height) / 2; // Take out countdown seconds - RVH20220309 //lblCountDown.Left = (this.Width - lblCountDown.Width) / 2; //lblCountDown.Top = (this.Height - lblCountDown.Height) / 2; ResizeAllRaceCarLanes(); Invalidate(); } } }