-6

This is the screenshot of error

i just want to call btn click method when user press enter after entering data into textbox

  • welcome to stackoverflow! please provide some code snippet so everyone may help you better! – Shift 'n Tab Mar 07 '17 at 07:15
  • 2
    Better design, extract the logic in your button click into a separate method and call that! – SJFJ Mar 07 '17 at 07:16
  • @ShiftN'Tab screenshot contains code... check it .. both method are visible – Muhammad Hamza Mar 07 '17 at 07:16
  • On your question you cannot call an event method since it will only listen to a button click, the error says that the event method is not valid in the given context. instead of calling the event try to use button_name.PerformClick() instead. here is some example https://msdn.microsoft.com/en-us/library/system.windows.forms.button.performclick(v=vs.110).aspx – Shift 'n Tab Mar 07 '17 at 07:19
  • @SJFJ you are right, in this way it will work, but i just want to do like this way... can you help me in this way – Muhammad Hamza Mar 07 '17 at 07:20
  • @SJFJ i used button name also but error says that "An object reference is required for non-static field , method or property" – Muhammad Hamza Mar 07 '17 at 07:25

1 Answers1

0

Do put logic in the event handler methods. Create separate functions and call them instead. Anything else is just bad design and even if there is a way to do it, don't start using bad practices from start.

Gnqz
  • 3,292
  • 3
  • 25
  • 35