471,337 Members | 1,041 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

am desperate, still need help

Hi,
Sorry this is a long message, but I'm getting desperate (and worried). I
have a textbox (say, tb1) where the string is longer than the width of the
box. If I'm coming from the previous textbox (tb0) (by tabbing or pressing
enter or the down arrow), the text inside tb1 highlights and the cursor is at
the end of the string (so that the beginning of the string isn't visible).
If I type absolutely any key(s) other than Tab, Up, Down, or Enter, then
press either Tab, Up, Down, or Enter, the tb1.SelectionStart = 0; works so
that tb1 shows the string from the beginning, and moves on to highlight the
text in the next textbox. But if I press nothing before pressing Up, Down,
Tab, or Enter, tb1 keeps the string as it was when it was highlighted - the
beginning cut off, and then moves on to highlight the next box. It
completely ignores the tb1.SelectionStart = 0;. Here is what I write for the
KeyDown event for tb1:

private void tb1Down(object sender, System.Windows.Forms.KeyEventArgs e)
{
if ((e.KeyCode == Keys.Tab) || (e.KeyCode == Keys.Enter) || (e.KeyCode ==
Keys.Down) || (e.KeyCode == Keys.Up))
{
...save this and that...
tb1.SelectionStart = 0;
if (e.KeyCode == Keys.Up)
{tb0.SelectionStart = 0; tb0.SelectionLength = tb0.Text.Length; tb0.Focus();}
else {tb2.SelectionStart = 0; tb2.SelectionLength = tb2.Text.Length;
tb2.Focus();}
}

I've also tried to put tb1.SelectionStart = 0; in the tb1Leave event, and it
doesn't work:

private void tb1Leave(object sender, System.EventArgs e)
{
....save something else...
if (tb1.Focus() == true){MessageBox.Show("tb1Focus"); tb.SelectionStart = 0;}
}

Then I tried adding SendKeys.Send("{Home}"); just after the if (e.KeyCode ==
Tab || ...) statement in the KeyDown event, but what it did was send the Home
key to the next textbox so that the next textbox wasn't highlighted, and the
cursor was at the beginning of the text.
I have no idea what else I can try.
Please help!!!
Thanks again,
Mel
Dec 15 '05 #1
4 1236
KH
>> I have a textbox (say, tb1) where the string is longer than the width of
the box.

Make your text box wider.
"melanieab" wrote:
Hi,
Sorry this is a long message, but I'm getting desperate (and worried). I
have a textbox (say, tb1) where the string is longer than the width of the
box. If I'm coming from the previous textbox (tb0) (by tabbing or pressing
enter or the down arrow), the text inside tb1 highlights and the cursor is at
the end of the string (so that the beginning of the string isn't visible).
If I type absolutely any key(s) other than Tab, Up, Down, or Enter, then
press either Tab, Up, Down, or Enter, the tb1.SelectionStart = 0; works so
that tb1 shows the string from the beginning, and moves on to highlight the
text in the next textbox. But if I press nothing before pressing Up, Down,
Tab, or Enter, tb1 keeps the string as it was when it was highlighted - the
beginning cut off, and then moves on to highlight the next box. It
completely ignores the tb1.SelectionStart = 0;. Here is what I write for the
KeyDown event for tb1:

private void tb1Down(object sender, System.Windows.Forms.KeyEventArgs e)
{
if ((e.KeyCode == Keys.Tab) || (e.KeyCode == Keys.Enter) || (e.KeyCode ==
Keys.Down) || (e.KeyCode == Keys.Up))
{
...save this and that...
tb1.SelectionStart = 0;
if (e.KeyCode == Keys.Up)
{tb0.SelectionStart = 0; tb0.SelectionLength = tb0.Text.Length; tb0.Focus();}
else {tb2.SelectionStart = 0; tb2.SelectionLength = tb2.Text.Length;
tb2.Focus();}
}

I've also tried to put tb1.SelectionStart = 0; in the tb1Leave event, and it
doesn't work:

private void tb1Leave(object sender, System.EventArgs e)
{
...save something else...
if (tb1.Focus() == true){MessageBox.Show("tb1Focus"); tb.SelectionStart = 0;}
}

Then I tried adding SendKeys.Send("{Home}"); just after the if (e.KeyCode ==
Tab || ...) statement in the KeyDown event, but what it did was send the Home
key to the next textbox so that the next textbox wasn't highlighted, and the
cursor was at the beginning of the text.
I have no idea what else I can try.
Please help!!!
Thanks again,
Mel

Dec 15 '05 #2

melanieab wrote:
Hi,
Sorry this is a long message, but I'm getting desperate (and worried). I
have a textbox (say, tb1) where the string is longer than the width of the
box. If I'm coming from the previous textbox (tb0) (by tabbing or pressing
enter or the down arrow), the text inside tb1 highlights and the cursor is at
the end of the string (so that the beginning of the string isn't visible).
If I type absolutely any key(s) other than Tab, Up, Down, or Enter, then
press either Tab, Up, Down, or Enter, the tb1.SelectionStart = 0; works so
that tb1 shows the string from the beginning, and moves on to highlight the
text in the next textbox. But if I press nothing before pressing Up, Down,
Tab, or Enter, tb1 keeps the string as it was when it was highlighted - the
beginning cut off, and then moves on to highlight the next box. It
completely ignores the tb1.SelectionStart = 0;. Here is what I write for the
KeyDown event for tb1:

private void tb1Down(object sender, System.Windows.Forms.KeyEventArgs e)
{
if ((e.KeyCode == Keys.Tab) || (e.KeyCode == Keys.Enter) || (e.KeyCode ==
Keys.Down) || (e.KeyCode == Keys.Up))
{
...save this and that...
tb1.SelectionStart = 0;
if (e.KeyCode == Keys.Up)
{tb0.SelectionStart = 0; tb0.SelectionLength = tb0.Text.Length; tb0.Focus();}
else {tb2.SelectionStart = 0; tb2.SelectionLength = tb2.Text.Length;
tb2.Focus();}
}


Rather than SelectionStart and Selection length, just use the Select
method:

tb1.Select(0, 0);

in the leave event. It should work.

Dec 15 '05 #3
Thanks so much!!!!
(and happy holidays)
Mel

"Matt" wrote:

melanieab wrote:
Hi,
Sorry this is a long message, but I'm getting desperate (and worried). I
have a textbox (say, tb1) where the string is longer than the width of the
box. If I'm coming from the previous textbox (tb0) (by tabbing or pressing
enter or the down arrow), the text inside tb1 highlights and the cursor is at
the end of the string (so that the beginning of the string isn't visible).
If I type absolutely any key(s) other than Tab, Up, Down, or Enter, then
press either Tab, Up, Down, or Enter, the tb1.SelectionStart = 0; works so
that tb1 shows the string from the beginning, and moves on to highlight the
text in the next textbox. But if I press nothing before pressing Up, Down,
Tab, or Enter, tb1 keeps the string as it was when it was highlighted - the
beginning cut off, and then moves on to highlight the next box. It
completely ignores the tb1.SelectionStart = 0;. Here is what I write for the
KeyDown event for tb1:

private void tb1Down(object sender, System.Windows.Forms.KeyEventArgs e)
{
if ((e.KeyCode == Keys.Tab) || (e.KeyCode == Keys.Enter) || (e.KeyCode ==
Keys.Down) || (e.KeyCode == Keys.Up))
{
...save this and that...
tb1.SelectionStart = 0;
if (e.KeyCode == Keys.Up)
{tb0.SelectionStart = 0; tb0.SelectionLength = tb0.Text.Length; tb0.Focus();}
else {tb2.SelectionStart = 0; tb2.SelectionLength = tb2.Text.Length;
tb2.Focus();}
}


Rather than SelectionStart and Selection length, just use the Select
method:

tb1.Select(0, 0);

in the leave event. It should work.

Dec 15 '05 #4
melanieab wrote:

Hi Melanie,

Just add

((TextBox)sender).Select(0,0);

to the Leave event of the textbox.
-- Robert Kozak
www.TheArtOfProgrammingWith.net

Dec 16 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Dave Navarro | last post: by
5 posts views Thread by Tank | last post: by
5 posts views Thread by John Flynn | last post: by
1 post views Thread by Sajid | last post: by
7 posts views Thread by Ladysniper | last post: by

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.