another textbox question
-
Hi again, I have a textbox where the text is longer than the textbox width. When I type text in and leave, the beginning of the string shows, and focus goes on to the next box. But if I don't change the text (just tab through or whatever), the beginning of the string is cut off, leaving the end of the string visible. I do use
textbox.SelectionStart = 0;
, but it it only works if text is changed. Any suggestions??? Thanks again, Mel -
Hi again, I have a textbox where the text is longer than the textbox width. When I type text in and leave, the beginning of the string shows, and focus goes on to the next box. But if I don't change the text (just tab through or whatever), the beginning of the string is cut off, leaving the end of the string visible. I do use
textbox.SelectionStart = 0;
, but it it only works if text is changed. Any suggestions??? Thanks again, MelHm.. Maybe try to add [code]textbox.SelectionStart = 0;[/code] to the LostFocus event?
-
Hm.. Maybe try to add [code]textbox.SelectionStart = 0;[/code] to the LostFocus event?
That's the weird part, I have the FocusLeave event. private void txtBoxLeave(object sender, System.EventArgs e) {
textbox.SelectionStart = 0; ...
} Again, it works when the text is altered (even if it ends up being the exact same text), but not if nothing at all is done. :confused: Mel -
That's the weird part, I have the FocusLeave event. private void txtBoxLeave(object sender, System.EventArgs e) {
textbox.SelectionStart = 0; ...
} Again, it works when the text is altered (even if it ends up being the exact same text), but not if nothing at all is done. :confused: MelMaybe you can cheat a little bit?:
private void txtBoxLeave(object sender, System.EventArgs e) {
if (textbox.Text.Length > 0) {
textbox.SelectionStart = 1;
}
textbox.SelectionStart = 0;
}Dunno if this works though... Pompiedompiedom... ;)
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick
-
Maybe you can cheat a little bit?:
private void txtBoxLeave(object sender, System.EventArgs e) {
if (textbox.Text.Length > 0) {
textbox.SelectionStart = 1;
}
textbox.SelectionStart = 0;
}Dunno if this works though... Pompiedompiedom... ;)
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick
It just refuses to work. I even put a messagebox in before selectionstart = 1, and the messagebox showed up ok. But no beginning of the string. (If it helps anyone get any more ideas, pressing only the left arrow before leaving the textbox is enough to get the beginning part. And I did try adding a SendKeys.Send("{Left}") to the KeyDown event, but that only sent a left to the next textbox (even though it was before the command to focus on the next textbox), which I'm not sure I understand.) :wtf: Mel
-
It just refuses to work. I even put a messagebox in before selectionstart = 1, and the messagebox showed up ok. But no beginning of the string. (If it helps anyone get any more ideas, pressing only the left arrow before leaving the textbox is enough to get the beginning part. And I did try adding a SendKeys.Send("{Left}") to the KeyDown event, but that only sent a left to the next textbox (even though it was before the command to focus on the next textbox), which I'm not sure I understand.) :wtf: Mel
Ok, let me try again:
private void txtBoxLeave(object sender, System.EventArgs e) {
// You say that it only works if thge text is altered, so lets alter the text :P
// Again, i don't know if this works...
textbox.Text = textbox.Text + " "
textbox.Text = textbox.Text.SubString(0, textbox.Text.Length - 1)textbox.SelectionStart = 0;
}
Pompiedompiedom... ;)
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick
-
It just refuses to work. I even put a messagebox in before selectionstart = 1, and the messagebox showed up ok. But no beginning of the string. (If it helps anyone get any more ideas, pressing only the left arrow before leaving the textbox is enough to get the beginning part. And I did try adding a SendKeys.Send("{Left}") to the KeyDown event, but that only sent a left to the next textbox (even though it was before the command to focus on the next textbox), which I'm not sure I understand.) :wtf: Mel
-
Ok, let me try again:
private void txtBoxLeave(object sender, System.EventArgs e) {
// You say that it only works if thge text is altered, so lets alter the text :P
// Again, i don't know if this works...
textbox.Text = textbox.Text + " "
textbox.Text = textbox.Text.SubString(0, textbox.Text.Length - 1)textbox.SelectionStart = 0;
}
Pompiedompiedom... ;)
"..Commit yourself to quality from day one..it's better to do nothing at all than to do something badly.." -- Mark McCormick
-
Hey, Thanks a lot for looking again. I did try adding stuff to the text, but it was still refusing to work for me. I just posted what I found to do the trick before seeing your message. Anyway, thanks again, and happy holidays! Mel