× {{alert.msg}} Never ask again
Get notified about new tutorials RECEIVE NEW TUTORIALS

Using backspace to move back to previous textBox (C#)

Michael Perrenoud
Feb 06, 2015
<p>So to make this work you're going to need to make sure you run this code on <code>KeyUp</code>, but you also do not need multiple <code>KeyUp</code> handlers to do this. Consider this <code>KeyUp</code> handler:</p> <pre><code>private void textBox_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e) { var textBox = sender as TextBox; if (textBox == null) { return; } if (e.KeyCode == Keys.Back &amp;&amp; textBox.Text.Length == 0) { // this here of course being the Form // Select causes the form to select the previous control in the tab order this.Select(true, false); } } </code></pre> <p>Now just attach this handler to <strong>all</strong> text boxes that you want to behave this way and they'll all work.</p> <p>This tip was originally posted on <a href="http://stackoverflow.com/questions/23565232/Using%20backspace%20to%20move%20back%20to%20previous%20textBox%20(C#)/23565510">Stack Overflow</a>.</p>
comments powered by Disqus