using System; using System.Windows.Forms; using TradeIdeas.TIProData; namespace TradeIdeas.TIProGUI { public partial class AddThemeMessageBox : Form { public string ThemeName => txtBox_ThemeName.Text?.Trim(); public bool UseAsDefaultLayout => chkBox_UseAsDefaultLayout.Checked; public AddThemeMessageBox() { InitializeComponent(); Icon = GuiEnvironment.DefaultIcon.Icon; StartPosition = FormStartPosition.CenterParent; txtBox_ThemeName.Focus(); txtBox_ThemeName.Select(); } private void txtBoxThemeName_KeyPress(object sender, KeyPressEventArgs e) { // Check if the Ctrl key is pressed and the A key is also pressed if (Char.IsControl(e.KeyChar) || Char.IsWhiteSpace(e.KeyChar) || e.KeyChar == '\b') { // Allow the Ctrl+A combination return; } // Specify the allowed characters var allowedChars = "abcdefghijklmnopqrstuvwxyz0123456789_-!@#$%^*()"; // Check if the entered character is allowed if (!allowedChars.Contains(e.KeyChar.ToString().ToLower())) { // Block the input by setting the Handled property to true e.Handled = true; } } private void txtBoxThemeName_KeyUp(object sender, KeyEventArgs e) { if (IsThemeNameValid()) { this.btn_Save.Enabled = true; } else { this.btn_Save.Enabled = false; } if (e.KeyCode == Keys.Enter && this.btn_Save.Enabled) { this.DialogResult = DialogResult.OK; this.Close(); } } private bool IsThemeNameValid() { var themeName = txtBox_ThemeName.Text?.Trim() ?? string.Empty; var valid = themeName.HasValue(); return valid; } } }