How to determine which control on form has focus?

后端 未结 4 611
轻奢々
轻奢々 2021-01-11 10:20

I\'ve read elsewhere on here that to capture \"Enter\" key stroke in a text box and use it as if pushing a button I should set the KeyPreview property of the form to true an

4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-11 10:56

    Each form has a property for an "Accept" button & "Cancel" button, these are the buttons that get "clicked" when the user presses enter and escape respectively.

    You can change the default button as each control gets the focus (you can have one got focus event hander per button, and share it with a set of text boxes)

    If you do this then the apperance of the buttons change giving the user a visual cue telling them which button is the default.

    Alternatively, if you don't want to do that, you can use the "ActiveControl" property, and test to see which of the sets of text boxes it belongs to.

    Have you asked yourself, what should the default button be if it's not one of thse text boxes?

提交回复
热议问题