public TextBoxForm() { ApplyButton = new Button(); DenyButton = new Button(); TextBox = new ValidableTextBox(); if (TextBox is not null) { TextBox.Location = new Point(0, 0); TextBox.Size = new Size(500, 24); TextBox.TextChanged += OnTextBoxTextChanged; TextBox.ValidateChanged += () => ValidateChanged?.Invoke(); Controls.Add(TextBox); } ApplyButton.Text = @"Apply"; ApplyButton.Location = new Point(1, 24); ApplyButton.Size = new Size(244, 28); ApplyButton.Click += (sender, args) => { DialogResult = DialogResult.OK; Close(); }; DenyButton.Text = @"Cancel"; DenyButton.Location = new Point(255, 24); DenyButton.Size = new Size(244, 28); DenyButton.Click += (sender, args) => { DialogResult = DialogResult.Cancel; Close(); }; Text = @"Set value"; ClientSize = new Size(500, 54); FormBorderStyle = FormBorderStyle.FixedSingle; AcceptButton = ApplyButton; CancelButton = DenyButton; MaximizeBox = false; Controls.Add(ApplyButton); Controls.Add(DenyButton); }
protected virtual void OnValidateChanged(bool isValid) { ValidateChanged?.Invoke(this, isValid); }