hello everyone, i am still a newbie in programming so pls excuse my stupid question,
i am making a programm which consists of several text boxes next to eachother and under each other so i need to make the keyboard arrow keys functional so that the user could move the cursor from one another using the keyboard arrow keys to make it easier to input his data. could someone be so gentle and tell me how to do it thanks and regards.
Loading
azzo trigoPosted May 4, 2013, 1:52 PM
Javeed M ShaikhPosted May 1, 2013, 2:40 PM
TextBox tb = (TextBox)sender;
with
System.Windows.Forms.TextBox tb = (TextBox)sender;
azzo trigoPosted May 1, 2013, 2:24 PM
thanks again guys.
Ravikumar GPosted Apr 24, 2013, 3:02 AM
It is better to use Jquery for this type for situation.
In Jquery there is a function called Next() and Prev(), with this function you can traverse to the next and previous element . Call these functions based on the arrow keys.
Once go through the below links you will get an idea...
http://api.jquery.com/prev/
http://api.jquery.com/next/
shafeeq shafeeqPosted Apr 24, 2013, 12:07 AM
please check you form designer class .
you are missing that textbox change event in form code window.
You can write this code in your Form1.cs class
protected void 'textBox1_TextChanged(object sender,KeyEventArgs e)
{
}
Or you can delete that error line from your designer class..but you cant access the event
azzo trigoPosted Apr 23, 2013, 1:05 PM
azzo trigoPosted Apr 23, 2013, 12:26 PM
VulpesPosted Apr 18, 2013, 10:24 AM
However, if you want to give your textboxes completely different names, then you can put them into an array first and then use something similar to my approach.
shafeeq shafeeqPosted Apr 18, 2013, 10:15 AM
Riddhi ValechaPosted Apr 18, 2013, 1:43 AM
I have made CheckKeys() Method. It is working fine.
If you are satisfied, do mark the answer as Accepted Answer.
VulpesPosted Apr 17, 2013, 6:56 PM
I've just tried the code myself and it seems to be working fine.
Can't really think what exception you could get on tb.Focus(). If tb were null, then it should have shown up in one of the earlier lines.
What is the actual exception you're getting?
azzo trigoPosted Apr 17, 2013, 4:10 PM
VulpesPosted Apr 17, 2013, 12:06 PM
The first thing to do is to use the same KeyDown handler for all 60 of them. Having added one for the first textbox, just select it from the dropdown in the Properties Box for the other 59.
The code for the handler will now be as follows (off top of my head so may not be quite right):
private void textBox1_KeyDown(object sender, KeyEventArgs e)
{
Textbox tb = (TextBox)sender;
int number = int.Parse(tb.Name.Substring(7));
if (e.KeyData == Keys.Right)
{
if (number < 60)
{
tb = (TextBox)this.Controls["textBox" + (number + 1).ToString()];
}
else
{
tb = (TextBox)this.Controls["textBox1"]; // wrap around to number 1
}
tb.Focus();
}
else if (e.KeyData == Keys.Left)
{
if (number == 1)
{
tb = (TextBox)this.Controls["textBox60"]; // wrap around to number 60
}
else
{
tb = (TextBox)this.Controls["textBox" + (number - 1).ToString()];
}
tb.Focus();
}
}
The code for the up and down keys will depend on how the textboxes are arranged on the form.
azzo trigoPosted Apr 17, 2013, 11:01 AM
Riddhi ValechaPosted Apr 17, 2013, 8:27 AM
One option is - set the tabindex property of the textboxes.
Eg-
Say we have 5 Textbox controls
ID-Textbox1,TabIndex=1
ID-Textbox2,TabIndex=2
ID-Textbox3,TabIndex=3
ID-Textbox4,TabIndex=4
ID-Textbox5,TabIndex=5.
Now, Initially, the focus is on Textbox1.
When the user clicks "Tab" key on the keyboard, the focus will be on Textbox2.
Hope this helps.
azzo trigoPosted Apr 17, 2013, 6:57 AM
shafeeq shafeeqPosted Apr 17, 2013, 5:50 AM