473,416 Members | 1,559 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,416 software developers and data experts.

how to move cursor from one textbox to adjacent textbox using LEFT ARROW key

Hi friends ,
here is the sample code
private void txtbox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
if(e.KeyChar == 13) //enter
{
txtbox2.Focus();

}

if(e.KeyChar == 27) //escape
{

txtbox.Text = "";
}

if(e.KeyChar == 37)// LEFT ARROW KEY /*here the control is not coming inside*/
{
txtboxAdjacent.Enabled = true;
txtboxAdjacent.Focus();
}
}
In the above code when executed the control is not coming inside the if(e.KeyChar == 37) loop when i pressed
left arrow key on keyboard;

how to implement the Arrow Keys in the KeyPress_event or in any other event?

hey guys plz help me out this.
-------------@@@@@@@@@@@@@---------------------------------------------------

Nov 15 '05 #1
7 5744

Try using the KeyDown event instead:

private void textBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if( e.KeyCode == Keys.Left)
{
textBox2.Focus();
e.Handled = true;
}
}
You will probably want to put in additional checking to make sure that's
what they really want - this will let the user move the cursor in the
textbox with the right arrow, but not the left. This would be a bit
confusing to me!

Hope this helps
- Philip
"Seash" <an*******@discussions.microsoft.com> wrote in message
news:F3**********************************@microsof t.com...
Hi friends ,
here is the sample code
private void txtbox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) {
if(e.KeyChar == 13) //enter
{
txtbox2.Focus();

}

if(e.KeyChar == 27) //escape
{

txtbox.Text = "";
}

if(e.KeyChar == 37)// LEFT ARROW KEY /*here the control is not coming inside*/ {
txtboxAdjacent.Enabled = true;
txtboxAdjacent.Focus();
}
}
In the above code when executed the control is not coming inside the if(e.KeyChar == 37) loop when i pressed left arrow key on keyboard;

how to implement the Arrow Keys in the KeyPress_event or in any other event?
hey guys plz help me out this.
-------------@@@@@@@@@@@@@------------------------------------------------ ---

Nov 15 '05 #2
thxs philip,
But there is a problem, in the middle of text of the textbox if i press left arrow key control straight away goes to the adjacent one, this one bugging me plz help me.

----- Philip Rieck wrote: -----
Try using the KeyDown event instead:

private void textBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if( e.KeyCode == Keys.Left)
{
textBox2.Focus();
e.Handled = true;
}
}
You will probably want to put in additional checking to make sure that's
what they really want - this will let the user move the cursor in the
textbox with the right arrow, but not the left. This would be a bit
confusing to me!

Hope this helps
- Philip
"Seash" <an*******@discussions.microsoft.com> wrote in message
news:F3**********************************@microsof t.com...
Hi friends ,
here is the sample code
private void txtbox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) {
if(e.KeyChar == 13) //enter
{
txtbox2.Focus();
}
if(e.KeyChar == 27) //escape {
txtbox.Text = "";

}
if(e.KeyChar == 37)// LEFT ARROW KEY /*here the control is not coming inside*/ {
txtboxAdjacent.Enabled = true;
txtboxAdjacent.Focus();
}
} In the above code when executed the control is not coming inside the
if(e.KeyChar == 37) loop when i pressed
left arrow key on keyboard;
how to implement the Arrow Keys in the KeyPress_event or in any other
event? hey guys plz help me out this.

-------------@@@@@@@@@@@@@------------------------------------------------

---

Nov 15 '05 #3
------seash wrote-----------------------
Cursor should not move to the immidiate text box if there is text in the text box , it should pass each and every character before moving to the adgacent texbox

hope someone out there to crack this!
---seash

----- seash wrote: -----

thxs philip,
But there is a problem, in the middle of text of the textbox if i press left arrow key control straight away goes to the adjacent one, this one bugging me plz help me.

----- Philip Rieck wrote: -----
Try using the KeyDown event instead:

private void textBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if( e.KeyCode == Keys.Left)
{
textBox2.Focus();
e.Handled = true;
}
}
You will probably want to put in additional checking to make sure that's
what they really want - this will let the user move the cursor in the
textbox with the right arrow, but not the left. This would be a bit
confusing to me!

Hope this helps
- Philip
"Seash" <an*******@discussions.microsoft.com> wrote in message
news:F3**********************************@microsof t.com...
Hi friends ,
here is the sample code
private void txtbox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e) {
if(e.KeyChar == 13) //enter
{
txtbox2.Focus();
}
if(e.KeyChar == 27) //escape {
txtbox.Text = "";

}
if(e.KeyChar == 37)// LEFT ARROW KEY /*here the control is not coming inside*/ {
txtboxAdjacent.Enabled = true;
txtboxAdjacent.Focus();
}
} In the above code when executed the control is not coming inside the
if(e.KeyChar == 37) loop when i pressed
left arrow key on keyboard;
how to implement the Arrow Keys in the KeyPress_event or in any other
event? hey guys plz help me out this.

-------------@@@@@@@@@@@@@------------------------------------------------

---

Nov 15 '05 #4
Test the selectionstart :

private void textBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if( e.KeyCode == Keys.Left)
{
if(textBox1.SelectionStart == 0)
{
textBox2.Focus();
e.Handled = true;
}
}
}
If your textbox is right-to-left text instead of left-to-right, then test if
the selectionstart is equal to textbox1.text.length instead of 0.
"seash" <an*******@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
------seash wrote-----------------------
Cursor should not move to the immidiate text box if there is text in the text box , it should pass each and every character before moving to the
adgacent texbox
hope someone out there to crack this!
---seash

----- seash wrote: -----

thxs philip,
But there is a problem, in the middle of text of the textbox if i press left arrow key control straight away goes to the adjacent one, this
one bugging me plz help me.
----- Philip Rieck wrote: -----
Try using the KeyDown event instead:

private void textBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if( e.KeyCode == Keys.Left)
{
textBox2.Focus();
e.Handled = true;
}
}
You will probably want to put in additional checking to make sure that's what they really want - this will let the user move the cursor in the textbox with the right arrow, but not the left. This would be a bit confusing to me!

Hope this helps
- Philip
"Seash" <an*******@discussions.microsoft.com> wrote in message
news:F3**********************************@microsof t.com...
> Hi friends ,
> here is the sample code
> private void txtbox_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
> {
> if(e.KeyChar == 13) //enter
> {
> txtbox2.Focus();
>> }
>> if(e.KeyChar == 27) //escape

> {
>> txtbox.Text = "";

> }
>> if(e.KeyChar == 37)// LEFT ARROW KEY /*here the control
is not coming inside*/
> {
> txtboxAdjacent.Enabled = true;
> txtboxAdjacent.Focus();
> }
> }
>>> In the above code when executed the control is not
coming inside the if(e.KeyChar == 37) loop when i pressed
> left arrow key on keyboard;
>> how to implement the Arrow Keys in the KeyPress_event or
in any other event? >> hey guys plz help me out this.




-------------@@@@@@@@@@@@@------------------------------------------------
---
>

Nov 15 '05 #5
Thxs Philip
this statement "e.Handled = true;" is necessary to include?, is there any cases of events not executing after events invocation? will the above statement gives any exception if events is not handled

-- seash
----- Philip Rieck wrote: ----

Test the selectionstart

private void textBox1_KeyDown(object sender
System.Windows.Forms.KeyEventArgs e

if( e.KeyCode == Keys.Left

if(textBox1.SelectionStart == 0

textBox2.Focus()
e.Handled = true

If your textbox is right-to-left text instead of left-to-right, then test i
the selectionstart is equal to textbox1.text.length instead of 0
"seash" <an*******@discussions.microsoft.com> wrote in messag
news:CE**********************************@microsof t.com..
------seash wrote----------------------
Cursor should not move to the immidiate text box if there is text in th text box , it should pass each and every character before moving to th
adgacent texbo
hope someone out there to crack this

---seas
----- seash wrote: ----
thxs philip

But there is a problem, in the middle of text of the textbox if

press left arrow key control straight away goes to the adjacent one, thi
one bugging me plz help me
----- Philip Rieck wrote: ----
Try using the KeyDown event instead

private void textBox1_KeyDown(object sender

System.Windows.Forms.KeyEventArgs e

if( e.KeyCode == Keys.Left

textBox2.Focus()
e.Handled = true

You will probably want to put in additional checking to mak
sure that' what they really want - this will let the user move the curso in th textbox with the right arrow, but not the left. This would be bi confusing to me
Hope this help - Phili "Seash" <an*******@discussions.microsoft.com> wrote in messag news:F3**********************************@microsof t.com..
Hi friends
here is the sample cod
private void txtbox_KeyPress(object sender

System.Windows.Forms.KeyPressEventArgs e

if(e.KeyChar == 13) //ente

txtbox2.Focus()

if(e.KeyChar == 27) //escap

txtbox.Text = ""

if(e.KeyChar == 37)// LEFT ARROW KEY /*here the contro

is not comin inside*

txtboxAdjacent.Enabled = true
txtboxAdjacent.Focus()

In the above code when executed the control is no
coming inside th if(e.KeyChar == 37) loop when i presse
left arrow key on keyboard
how to implement the Arrow Keys in the KeyPress_event o
in any othe event hey guys plz help me out this

-------------@@@@@@@@@@@@@-----------------------------------------------

--

Nov 15 '05 #6
The statement "e.Handled = true" will simply cause the base class to stop
processing the KeyDown event. This will keep it from performing the normal
action of moving the cursor. Since in this case you don't care, it's not
entirely needed.
The event will still be handled, but the textbox assumes that you are going
to do the right thing with the message, it will simply ignore the keypress.
You don't need to worry about exceptions due to unhandled events.

"seash" <an*******@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
Thxs Philip,
this statement "e.Handled = true;" is necessary to include?, is there any cases of events not executing after events invocation? will the above
statement gives any exception if events is not handled?
-- seash
----- Philip Rieck wrote: -----

Test the selectionstart :

private void textBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if( e.KeyCode == Keys.Left)
{
if(textBox1.SelectionStart == 0)
{
textBox2.Focus();
e.Handled = true;
}
}
}
If your textbox is right-to-left text instead of left-to-right, then test if the selectionstart is equal to textbox1.text.length instead of 0.
"seash" <an*******@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
> ------seash wrote-----------------------
> Cursor should not move to the immidiate text box if there is text in the
text box , it should pass each and every character before moving to the adgacent texbox >> hope someone out there to crack this! > ---seash
>> ----- seash wrote: -----
>> thxs philip,

> But there is a problem, in the middle of text of the textbox if i press left arrow key control straight away goes to the adjacent one, this one bugging me plz help me. >> ----- Philip Rieck wrote: -----
>>> Try using the KeyDown event instead:
>> private void textBox1_KeyDown(object sender, > System.Windows.Forms.KeyEventArgs e)
> {
> if( e.KeyCode == Keys.Left)
> {
> textBox2.Focus();
> e.Handled = true;
> }
> }
>>> You will probably want to put in additional checking to make sure that's
> what they really want - this will let the user move the cursor
in the
> textbox with the right arrow, but not the left. This
would be a bit
> confusing to me!
>> Hope this helps

> - Philip
>>> "Seash" <an*******@discussions.microsoft.com> wrote in

message > news:F3**********************************@microsof t.com... >> Hi friends ,
>> here is the sample code
>> private void txtbox_KeyPress(object sender,

> System.Windows.Forms.KeyPressEventArgs e)
>> {
>> if(e.KeyChar == 13) //enter
>> {
>> txtbox2.Focus();
>>> }
>>> if(e.KeyChar == 27) //escape
>> {
>>> txtbox.Text = "";
>> }
>>> if(e.KeyChar == 37)// LEFT ARROW KEY /*here the control

is not coming
> inside*/
>> {
>> txtboxAdjacent.Enabled = true;
>> txtboxAdjacent.Focus();
>> }
>> }
>>>> In the above code when executed the control is not

coming inside the
> if(e.KeyChar == 37) loop when i pressed
>> left arrow key on keyboard;
>>> how to implement the Arrow Keys in the KeyPress_event or

in any other
> event?
>>> hey guys plz help me out this.



-------------@@@@@@@@@@@@@----------------------------------------------- - > ---
>>

Nov 15 '05 #7
The statement "e.Handled = true" will simply cause the base class to stop
processing the KeyDown event. This will keep it from performing the normal
action of moving the cursor. Since in this case you don't care, it's not
entirely needed.
The event will still be handled, but the textbox assumes that you are going
to do the right thing with the message, it will simply ignore the keypress.
You don't need to worry about exceptions due to unhandled events.

"seash" <an*******@discussions.microsoft.com> wrote in message
news:0C**********************************@microsof t.com...
Thxs Philip,
this statement "e.Handled = true;" is necessary to include?, is there any cases of events not executing after events invocation? will the above
statement gives any exception if events is not handled?
-- seash
----- Philip Rieck wrote: -----

Test the selectionstart :

private void textBox1_KeyDown(object sender,
System.Windows.Forms.KeyEventArgs e)
{
if( e.KeyCode == Keys.Left)
{
if(textBox1.SelectionStart == 0)
{
textBox2.Focus();
e.Handled = true;
}
}
}
If your textbox is right-to-left text instead of left-to-right, then test if the selectionstart is equal to textbox1.text.length instead of 0.
"seash" <an*******@discussions.microsoft.com> wrote in message
news:CE**********************************@microsof t.com...
> ------seash wrote-----------------------
> Cursor should not move to the immidiate text box if there is text in the
text box , it should pass each and every character before moving to the adgacent texbox >> hope someone out there to crack this! > ---seash
>> ----- seash wrote: -----
>> thxs philip,

> But there is a problem, in the middle of text of the textbox if i press left arrow key control straight away goes to the adjacent one, this one bugging me plz help me. >> ----- Philip Rieck wrote: -----
>>> Try using the KeyDown event instead:
>> private void textBox1_KeyDown(object sender, > System.Windows.Forms.KeyEventArgs e)
> {
> if( e.KeyCode == Keys.Left)
> {
> textBox2.Focus();
> e.Handled = true;
> }
> }
>>> You will probably want to put in additional checking to make sure that's
> what they really want - this will let the user move the cursor
in the
> textbox with the right arrow, but not the left. This
would be a bit
> confusing to me!
>> Hope this helps

> - Philip
>>> "Seash" <an*******@discussions.microsoft.com> wrote in

message > news:F3**********************************@microsof t.com... >> Hi friends ,
>> here is the sample code
>> private void txtbox_KeyPress(object sender,

> System.Windows.Forms.KeyPressEventArgs e)
>> {
>> if(e.KeyChar == 13) //enter
>> {
>> txtbox2.Focus();
>>> }
>>> if(e.KeyChar == 27) //escape
>> {
>>> txtbox.Text = "";
>> }
>>> if(e.KeyChar == 37)// LEFT ARROW KEY /*here the control

is not coming
> inside*/
>> {
>> txtboxAdjacent.Enabled = true;
>> txtboxAdjacent.Focus();
>> }
>> }
>>>> In the above code when executed the control is not

coming inside the
> if(e.KeyChar == 37) loop when i pressed
>> left arrow key on keyboard;
>>> how to implement the Arrow Keys in the KeyPress_event or

in any other
> event?
>>> hey guys plz help me out this.



-------------@@@@@@@@@@@@@----------------------------------------------- - > ---
>>

Nov 15 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Arno | last post by:
Hello, I am trying to edit a textbox which contains a number. When focus is on the textbox, and a user press the "arrow up", I would like the textbox value to increase of 100, and at the opposite...
5
by: Marcos Ribeiro | last post by:
Does anyone knows how to change the cursor when the mouse is over a selected text on a textbox or richtextbox? (similar effect on Window Wordpad) From IBeam to Arrow for drag & drop purpouses...
9
by: DotNetShadow | last post by:
Hi Guys, I have been having this problem recently where I have a form with a textbox and button, if in the button event I have the following: Private Sub Button1_Click(ByVal sender As...
2
by: Rader | last post by:
As the textbox is focused,if I press the keys up/down arrow instead of other keys like a,b,c...... the input cursor moves left and right.Now its the problem,I want the cursor stay where it...
4
by: David Veeneman | last post by:
I'm creating a UserControl that uses a LinkLabel. For reasons that I won't bore everyone with, I don't want the LinkLable to show the default hand cursor when the mouse enters the control. Should...
1
by: VanKha | last post by:
How to move the cursor( I'm programming with Win32 console applications in visual c++ 6.0) by letting the user type in arrow keys(and obviously, I will then have some variable column and row and use...
2
by: sandromani | last post by:
Hello, I was wondering if there was a way (in c++) to move the cursor when pressing the arrow keys instead of getting ^[[C resp. ^[[D (left resp. right arrow) in the cin input - I am using linux. I...
0
by: ivan | last post by:
Hello, How do I move the keyboard cursor position in a Tix.HList? I am using an HList with the right mouse button bound to pop up a menu. If the right click is done on an unselected item, I...
5
by: michels287 | last post by:
Right now I have a touchscreen with a virual keyboard. I would like to create arrow keys. If the user messed up the inputted text, he can move the blinking cursor left one space at a time between...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.