am desperate, still need help

G

Guest

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
 
G

Guest

I have a textbox (say, tb1) where the string is longer than the width of
the box.

Make your text box wider.
 
M

Matt

melanieab said:
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.
 
G

Guest

Thanks so much!!!!
(and happy holidays)
Mel

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

tb1.Select(0, 0);

in the leave event. It should work.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top