1

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

2
  • 1
    Can you please define your issue more clearly? What you describe does not make sense as the TextChanged event will usually be raised on every character and on the enter key press that you fake. What are you actually trying to achieve? Commented Apr 15, 2011 at 15:33
  • 1
    Are you looking for AcceptButton which would be default button when enter is pressed on the form Commented Apr 15, 2011 at 15:34

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

0

You can do it like this

button1_Click(null, null)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.