问题
On some occasions, when focus is set to a particular textbox, the cursor parks itself before the text like this:
Yet, the TextBox has a GotFocus handler that explicitly selects all the text:
private void txtQty_GotFocus(object sender, EventArgs e)
{
try
{
if (deviceInfo.isKeyboardShown())
{
SipShowIM(SIPF_OFF);
}
txtQty.SelectAll();
txtQty.BackColor = Color.Yellow;
}
catch (Exception ex)
{
NRBQ.ExceptionHandler(ex, "frmEntry.txtQty.GotFocus");
}
}
Also, the BackColor is not set to yellow. But the txtQty_GotFocus handler is never unhooked. How could it be that it is not firing? Are there certain conditions under which focus can be programmatically set to a TextBox without the GotFocus event firing?
UPDATE
This was "solved" by adding another call to txtQty.Focus();
Why that was necessary, when txtQty already had focus (with a blinking cursor) I don't know. And why the textbox getting focus/cursor didn't SelectAll() as well as yellowify the background of the textbox still has me verblueffed.
来源:https://stackoverflow.com/questions/24790704/how-could-a-textboxs-cursor-move-to-the-beginning-of-the-text-after-calling-sel