我有一个文本框数组
_textBox = new TextBox[]
{
textBox1,
textBox2,
textBox3,
textBox4,
textBox5,
textBox6,
textBox7,
textBox8,
textBox9
};
我用这个方法通过击键在这个数组中向上/向下移动:
private void textBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter || e.KeyCode == Keys.Down)
{
if (KeyIndex < RowsLimit - 1)
++KeyIndex;
else
{
if (KeyIndex != 7)
paymntgrp.Visible = false;
SaveBtn.Select();
KeyIndex = 0;
return;
}
_textBox[KeyIndex].SelectionStart = 0;
_textBox[KeyIndex].SelectionLength = _textBox[KeyIndex].Text.Length;
_textBox[KeyIndex].Select();
if (KeyIndex != 7)
paymntgrp.Visible = false;
else
paymntgrp.Visible = true;
}
else
{
if (e.KeyCode == Keys.Up)
{
if (KeyIndex > 0)
--KeyIndex;
_textBox[KeyIndex].SelectionStart = 0;
_textBox[KeyIndex].SelectionLength = _textBox[KeyIndex].Text.Length;
_textBox[KeyIndex].Select();
if (KeyIndex != 7)
paymntgrp.Visible = false;
else
paymntgrp.Visible = true;
}
}
}
但是,当我在文本框之一中随机单击鼠标时,Keyindex 保持不变并从原来的位置继续。
如何将 Keyindex 设置为鼠标的位置。?
我应该在每个文本框 Keyindex = 0, Keyindex= 1 ...下写吗?(在方法 Mouse_Click for ex 下)
还是有更有效的方法?