using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace KeyPressTest
{
static class Program
{
[STAThread]
static void Main ()
{
Application.EnableVisualStyles ();
Application.SetCompatibleTextRenderingDefault (false);
Application.Run (new TestForm ());
}
public class TestForm : Form
{
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label1;
private CheckBox cb;
public TestForm ()
{
cb = new CheckBox ();
cb.Text = "Ignore Enter";
Controls.Add (cb);
this.textBox1 = new System.Windows.Forms.TextBox ();
this.label1 = new System.Windows.Forms.Label ();
this.SuspendLayout ();
this.textBox1.Location = new System.Drawing.Point (16, 68);
this.textBox1.Multiline = true;
this.textBox1.Size = new System.Drawing.Size (332, 84);
this.textBox1.TabIndex = 0;
this.textBox1.KeyPress += new System.Windows.Forms.KeyPressEventHandler (this.textBox1_KeyPress);
this.label1.Location = new System.Drawing.Point (16, 16);
this.label1.Size = new System.Drawing.Size (332, 48);
this.label1.TabIndex = 1;
this.label1.Text = "To reproduce the problem, type \"12345\" and the hit the Return (Enter) key. The character \"3\" and the Return key should be ignored. Instead, only the character 3 is ingored.";
this.ClientSize = new System.Drawing.Size (364, 164);
this.Controls.Add (this.label1);
this.Controls.Add (this.textBox1);
this.Text = "Form1";
this.ResumeLayout (false);
this.PerformLayout ();
}
private void textBox1_KeyPress (object sender, KeyPressEventArgs e)
{
if (cb.Checked)
if (e.KeyChar == '3' || e.KeyChar == '\r')
e.Handled = true;
}
}
}
}