using System; using System.Drawing; using System.Windows.Forms; namespace TradeIdeas.TIProGUI.Charting.Controls.CurrentPosition { public partial class CurrentPositionDisplayControl : UserControl { public CurrentPositionDisplayControl() { InitializeComponent(); this.Margin = new Padding(2, 4, 2, 2); this.BackColor = Color.FromArgb(0, 64, 128); this.SharesProfitOrLossLabel.Font = new Font("Microsoft Sans Serif", 7F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(0))); this.SharesProfitOrLossLabel.Padding = new Padding(0, 0, 0, 3); this.SharesCountLabel.Font = new Font("Microsoft Sans Serif", 7F, FontStyle.Bold, GraphicsUnit.Point, ((byte)(0))); this.SharesCountLabel.Padding = new Padding(0, 0, 0, 3); } public void SetDisplayText(double shares, double averageCost, double lastPrice) { if (shares == 0) Hide(); var isPositive = shares >= 0; this.SharesCountLabel.Text = (isPositive ? "+" : "") + shares + " shrs @ " + averageCost.ToString("N2"); this.SharesProfitOrLossLabel.Left = this.SharesCountLabel.Width + 1; var sharesAverageCost = shares * averageCost; var currentSharesValue = shares * lastPrice; var totalProfit = currentSharesValue - sharesAverageCost; var isTotalProfitPositive = totalProfit >= 0; this.SharesProfitOrLossLabel.Text = (isTotalProfitPositive ? "+" : "-") + "$" + Math.Abs(totalProfit).ToString("N2"); this.SharesProfitOrLossLabel.ForeColor = isTotalProfitPositive ? Color.LimeGreen : Color.Red; } } }