我已经构建了一个 Custom MaskedTextBox
,更改了 和 的值,BeepOnError
并AsciiOnly
为 . 添加了一个客户 EventHandler MaskInputRejected
。我构建了这个类,当我把它放在我的表单上时,我添加到自定义类的自定义属性会出现,但是对和
的更改不会,自定义 EventHandler 也不会触发。 BeepOnError
AsciiOnly
有人可以指出我做错了什么吗?如果我手动将 EventHandler 添加到表单中,它可以正常工作。
自定义类;
public partial class BaseMaskedTextBox : MaskedTextBox
{
public string gsOrigValue { get; set; }
public string gsReadOnlyMode { get; set; }
public bool gbIsString { get; set; }
...
private void BaseMaskedTextBox_MaskInputRejected(Object sender, MaskInputRejectedEventArgs e)
{
System.Text.StringBuilder messageBoxCS = new System.Text.StringBuilder();
messageBoxCS.AppendFormat("{0} = {1}", "Character Position", e.Position);
messageBoxCS.AppendLine();
messageBoxCS.AppendFormat("{0} = {1}", "Reason Rejected", e.RejectionHint);
messageBoxCS.AppendLine();
MessageBox.Show(messageBoxCS.ToString(), "Input Mask Invalid...");
}
在InitializeComponent(
):
this.BaseMaskedTextBox1.AsciiOnly = <b>true</b>;
this.BaseMaskedTextBox1.BeepOnError = <b>true</b>;
this.BaseMaskedTextBox1.Font = new System.Drawing.Font("Microsoft Sans Serif", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.BaseMaskedTextBox1.Location = new System.Drawing.Point(0, 0);
this.BaseMaskedTextBox1.Name = "BaseMaskedTextBox1";
this.BaseMaskedTextBox1.Size = new System.Drawing.Size(100, 21);
this.BaseMaskedTextBox1.TabIndex = 0;
this.BaseMaskedTextBox1.MaskInputRejected += new System.Windows.Forms.MaskInputRejectedEventHandler(this.BaseMaskedTextBox_MaskInputRejected);
this.ResumeLayout(false);