Lukas
Lukas

Reputation: 399

.net winforms TextBox programmatically press enter

How can I programmatically create Enter button press in .NET WinForms? I want on TextChanged event initialize Enter button press without user interrupt. Thanks

Upvotes: 1

Views: 2508

Answers (2)

trickdev
trickdev

Reputation: 599

System.Windows.Forms.Button PerformClick

myButton.PerformClick();

That will perform a click on myButton. I'd look into why you need to fake a button click, perhaps you could refactor to avoid this?

EDIT: On second thoughts, perhaps you meant the Enter key. In this case you could use:

SendKeys.Send("{ENTER}");

Still look into the need for this though, it isn't something you should normally have to do.

Upvotes: 2

Subhash Lama
Subhash Lama

Reputation: 433

You can do it like this

button1_Click(null, null)

Upvotes: 0

Related Questions