public void OnBeforeNameChange(NameChangeEventArgs e) { if (BeforeNameChange != null) { BeforeNameChange(this, e); } }
public override void SetValue(object component, object value) { string s = value as string; if (!string.IsNullOrEmpty(s)) { NameChangeEventArgs ce = new NameChangeEventArgs(s); _owner.OnBeforeNameChange(ce); if (!ce.Cancel) { _owner.Name = s; _owner.OnAfterNameChange(); } } }
private void buttonOK_Click(object sender, EventArgs e) { DataName = textBox1.Text.Trim(); if (string.IsNullOrEmpty(DataName)) { MessageBox.Show(this, "Value name cannot be empty", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (_validateName && !NameChangeEventArgs.IsValidName(DataName)) { MessageBox.Show(this, Resource1.InvalidName, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } else { if (string.Compare(_oldName, DataName, StringComparison.OrdinalIgnoreCase) != 0) { if (_names != null) { for (int i = 0; i < _names.Count; i++) { if (string.Compare(_names[i], DataName, StringComparison.OrdinalIgnoreCase) == 0) { MessageBox.Show(this, "Value name is in use", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return; } } } } int n = listBox1.SelectedIndex; if (n >= 0) { if (_useDefaultTypes) { switch (n) { case 0: DataType = typeof(string); break; case 1: DataType = typeof(Int32); break; case 2: DataType = typeof(double); break; case 3: DataType = typeof(bool); break; case 4: DataType = typeof(DateTime); break; default: DataType = typeof(string); break; } } else { DataType = _types[listBox1.Items[n] as string]; } this.DialogResult = DialogResult.OK; } } } }