locked
how to disable mouse events on textboxes RRS feed

  • Question

  • I am working with winforms and I want that unless user clicks a button my all the controls in form

    should not have any mouse events.I do not wish to use readonly property or enable property of
    textboxes.textboxes shld not get focus once clicked .how do i disable those events?

    Thursday, July 14, 2011 12:06 PM

Answers

  • You can handle Enter event of all textboxes, and if some condition is not met (user has not clicked the button) set focus back to the button (or some other control of your choice.

    Be sure to read the documentation on Enter event because it doesn't recommend such practice. I have tested it though on a simple case and it works just fine.

    Do not attempt to set focus from within the Enter, GotFocus, Leave, LostFocus, Validating, or Validated event handlers. Doing so can cause your application or the operating system to stop responding. For more information, see the WM_KILLFOCUS topic in the "Keyboard Input Reference" section, and the "Message Deadlocks" section of the "About Messages and Message Queues" topic in the MSDN library at http://msdn.microsoft.com/library.

    bets regards,
    Vladimir 

    • Proposed as answer by Jie Bao Tuesday, July 19, 2011 5:04 AM
    • Marked as answer by Jie Bao Monday, July 25, 2011 9:55 AM
    Thursday, July 14, 2011 8:11 PM

All replies

  • You can handle Enter event of all textboxes, and if some condition is not met (user has not clicked the button) set focus back to the button (or some other control of your choice.

    Be sure to read the documentation on Enter event because it doesn't recommend such practice. I have tested it though on a simple case and it works just fine.

    Do not attempt to set focus from within the Enter, GotFocus, Leave, LostFocus, Validating, or Validated event handlers. Doing so can cause your application or the operating system to stop responding. For more information, see the WM_KILLFOCUS topic in the "Keyboard Input Reference" section, and the "Message Deadlocks" section of the "About Messages and Message Queues" topic in the MSDN library at http://msdn.microsoft.com/library.

    bets regards,
    Vladimir 

    • Proposed as answer by Jie Bao Tuesday, July 19, 2011 5:04 AM
    • Marked as answer by Jie Bao Monday, July 25, 2011 9:55 AM
    Thursday, July 14, 2011 8:11 PM
  • Another, you could put the controls in one panel, and then set the panel.Enable to false can disable all inner controls. And all events will not be fired.

    Sincerely,


    Bob Bao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 19, 2011 5:09 AM