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; namespace TIProSkunkWorksExtension { public partial class RaceWinnerControl : UserControl { private double _currentX; private double _currentY; private double _incrementX; private double _incrementY; private Point _endPoint; private string _symbol; public Action FinishMoveAction; public RaceWinnerControl(string symbol, int numWins, string basedOn, string sortOn, string raceTime, string finishDetails, Point startPoint, Point endPoint, Color textColor, Color backColor) { InitializeComponent(); _symbol = symbol; lblSymbol.Text = $"{symbol} - {numWins}"; //symbol; lblFinishDetails.Text = finishDetails; BackColor = backColor; lblSymbol.ForeColor = textColor; lblFinishDetails.ForeColor = textColor; // Add tool tip with details. toolTip1.SetToolTip(lblSymbol, $"Based On: {basedOn}, Sort On: {sortOn}, Race Time: {raceTime}"); toolTip1.SetToolTip(lblFinishDetails, finishDetails); // Set the control start point. this.Location = startPoint; _endPoint = endPoint; // Calculate the increments to move the control to the end point. _currentX = startPoint.X; _currentY = startPoint.Y; if (endPoint.X > _currentX) _incrementX = (endPoint.X - _currentX) / 100; else _incrementX = (_currentX - endPoint.X) / 100; if (endPoint.Y > _currentY) _incrementY = (endPoint.Y - _currentY) / 100; else _incrementY = (_currentY - endPoint.Y) / 100; } public void StartMoveTimer() { // Start the move timer. moveTimer.Start(); } private void moveTimer_Tick(object sender, EventArgs e) { // Stop the timer. moveTimer.Stop(); // Calculate the next increment position. Point currentPoint; if (_currentX < _endPoint.X) _currentX += _incrementX; else _currentX -= _incrementX; if (_currentY < _endPoint.Y) _currentY += _incrementY; else _currentY -= _incrementY; // See if we are at the end point. if (_currentX >= _endPoint.X || _currentY <= _endPoint.Y) { //moveTimer.Stop(); currentPoint = _endPoint; } else { currentPoint = new Point(Convert.ToInt32(Math.Round(_currentX)), Convert.ToInt32(Math.Round(_currentY))); } // Move the control to the next increment position. this.Location = currentPoint; // Restart time if needed. if (this.Location != _endPoint) moveTimer.Start(); else if (FinishMoveAction != null) FinishMoveAction(); } private void SendToExternalLinking(string symbol) { Panel raceWinnersPanel = Parent as Panel; if (raceWinnersPanel != null) { Panel raceWinnersHolderPanel = raceWinnersPanel.Parent as Panel; if (raceWinnersHolderPanel != null) { Panel finishLinePanel = raceWinnersHolderPanel.Parent as Panel; if (finishLinePanel != null) { RealTimeStockRaceForm realTimeStockRaceForm = finishLinePanel.Parent as RealTimeStockRaceForm; if (realTimeStockRaceForm != null) { realTimeStockRaceForm.SendToExternalLinking(symbol); } } } } } private void lblSymbol_Click(object sender, EventArgs e) { SendToExternalLinking(_symbol); } private void lblFinishDetails_Click(object sender, EventArgs e) { SendToExternalLinking(_symbol); } private void RaceWinnerControl_Click(object sender, EventArgs e) { SendToExternalLinking(_symbol); } } }