using System; using System.Drawing; using System.Windows.Forms; using TradeIdeas.TIProData; namespace TradeIdeas.TIProGUI { public partial class NumericTextBox : UserControl { private string Placeholder { get; set; } public event EventHandler OnKeyUpEnter; public float FontSize { set { if (value > 0) txtNumeric.Font = new Font("Microsoft Sans Serif", value, FontStyle.Regular); } } public int MaxLength { set { if (value > 0) txtNumeric.MaxLength = value; } } public string Value { get { return this.txtNumeric.Text; } set { this.txtNumeric.Text = value; } } /// /// Get/Set the text alignment for the textbox. /// public HorizontalAlignment TextAlign { get => txtNumeric.TextAlign; set => txtNumeric.TextAlign = value; } /// /// This user control is used to search for symbols and company names via a web service call. /// The control features auto-complete functionality. /// public NumericTextBox() : base() { InitializeComponent(); txtNumeric.AutoSize = false; } public void SetTextBoxPlaceholder(string placeholder) { this.Placeholder = placeholder; this.AddPlaceholder(); } private void txtNumberic_KeyPress(object sender, KeyPressEventArgs e) { if (!char.IsControl(e.KeyChar) && !char.IsDigit(e.KeyChar)) { e.Handled = true; } } private void txtNumberic_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter && this.OnKeyUpEnter != null) { this.OnKeyUpEnter(this, new EventArgs()); } } private void AddPlaceholder() { if (string.IsNullOrEmpty(this.Placeholder) || !string.IsNullOrEmpty(txtNumeric.Text)) { return; } txtNumeric.Text = this.Placeholder; txtNumeric.ForeColor = Color.Gray; } private void RemovePlaceholder() { if (string.IsNullOrEmpty(this.Placeholder)) { return; } if (this.Placeholder.EqualsIgnoreCase(txtNumeric.Text)) { txtNumeric.Text = string.Empty; txtNumeric.ForeColor = Color.Black; } } } }