Don't simulate pressing of a key. If it will do anything, you have an event handler attached anyway. Call that method directly instead of making the event call it.
There are two independent errors in your comment:
e.KeyCode = Keys.Enter;
is not possible since e.KeyCode
] is readonly. What do you want to achieve by doing this?
doesn't work because here your
is of type EventArgs
], but the method you're calling expects a KeyEventArgs
] as second parameter.
This is how you could get that to work:
private void MethodNameDescribingTheActionToTake()
private void textBox1_KeyDown(object sender, KeyEventArgs e)
private void checkbox_CheckedChanged(object sender, EventArgs e)
if (checkbox.Checked == true)
this.textBox1.Enabled = true;
if (checkbox.Checked == false)
this.textBox1.Enabled = false;