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.
[Edit]
There are two independent errors in your comment:
1.
e.KeyCode = Keys.Enter;
is not possible since
e.KeyCode[
^] is readonly. What do you want to achieve by doing this?
2.
textBox_KeyDown(sender,e);
doesn't work because here your
e
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)
{
MethodNameDescribingTheActionToTake();
}
private void checkbox_CheckedChanged(object sender, EventArgs e)
{
if (checkbox.Checked == true)
{
this.textBox1.Enabled = true;
}
if (checkbox.Checked == false)
{
textBox1.Clear();
MethodNameDescribingTheActionToTake();
this.textBox1.Enabled = false;
}
}
[/Edit]