Get the App
SLTechnology News&Howtos  ›  Development  › 

How to analyze the realization of C# enter switch focus

Shulou Source: shulou.com Published: 2022-06-02 11:43:29 09月24日 Update

This article introduces how to analyze the realization of C# enter switch focus, the content is very detailed, interested friends can refer to, hope to be helpful to you.

How can C# enter switch focus in WinForm and Web instead of TAB key? What is the specific method for C#C# to enter and switch focus? Let's take a look at the specific implementation process respectively.

C # enter to switch focus in WinForm:

There are text boxes textbox1 and textbox2, and now the cursor is in textbox1. How to make the cursor jump to textbox2 after pressing enter key to realize the function of tab key. First set the TabIndex property of textBox1 and textBox2 to 1 and 2, respectively.

Private void textBox1_KeyPress (object sender, System.Windows.Forms.KeyPressEventArgs e) {if (e.KeyChar = = (char) 13) {SendKeys.Send ("{Tab}");}}

C # enter to switch focus in Web:

On the client side (that is, within the .aspx page), add the following code between < head >.. < / head >:

< script language= "javascript" type= "text/javascript" > function keyDown () {var keycode=event.keyCode; var keyChar=String.fromCharCode (keycode); if (keycode==13) event.keyCode=9;}; * * Note: _ document.onkeydown=keyDown; < / script >

At the same time, add onkeydown= "keyDown ()" to < body >

On how to analyze the implementation of C# enter switch focus is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Focus toggle cursors content more help yes between code interests functions at the same time enter keys customers clients guys buddies attributes text Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Microsoft Docker Xiaomi MySQL