简体   繁体   中英

How to Detect Enter Key press in a text box which is used in a Custom View?

I have made a custom view in which i have used a search box which is a text box to search specific directory.When we press Enter key on the search box i search the directory and if found then refresh my custom browser to dispaly the new diretories content. but the problem is when i am in modal dialog then i could not detect the Enter key press event in the search box though i could detect the others key press event. When I press the Enter key it just change its focus to the windows Edit control and it does not execute any event like KeyPress/KeyDown etc.

Any suggestions

By default the Enter key is ignored by the TextBox when it is a single line control, as there is no need for it to have any response to an Enter key event. To overcome this you need to create a new class that derives from the TextBox and override the IsInputKey method. Inside here check if it is the Enter key and return True. This means the the key will be sent to the control because the control wants to process it. Then you can KeyDown for the TextBox as expected.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM