using CustomComponents.Exceptions; 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 CustomComponents { public partial class frameTextBox : UserControl { private string? _text; public event EventHandler taskHandler; public frameTextBox() { InitializeComponent(); } public string? Value { get { return _text; } set { _text = value; } } private void CheckBoxStateChanged(object sender, EventArgs e) { try { if (ruleCheckBox.Checked) { textBox.Enabled = false; if (!string.IsNullOrEmpty(_text)) { throw new ContentException(true); } } else { textBox.Enabled = true; if (string.IsNullOrEmpty(_text)) { throw new ContentException(false); } } } catch(ContentException ex) { taskHandler += (sender, e) => MessageBox.Show(ex.Message); } taskHandler?.Invoke(this, e); } private void CheckTextBoxValueType(object sender, EventArgs args) { Value = textBox.Text; try { Convert.ToInt32(Value); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } } }