【发布时间】:2017-09-11 03:43:37
【问题描述】:
每当我尝试清除 textBox2 时,我都会收到一条错误消息。我该如何解决这个问题?
private void textBox2_TextChanged(object sender, EventArgs e)
{
string HexKey = this.textBox2.Text;
if(textBox2.Focused)
int key = Convert.ToInt32(HexKey, 16);
}
private void button2_Click_1(object sender, EventArgs e)
{
textBox2.Clear();
}
[错误]: System.ArgumentOutOfRangeException: '索引超出范围。必须是非负数且小于集合的大小。 参数名称:startIndex'
【解决方案】:
private void textBox2_TextChanged(object sender, EventArgs e)
{
string HexKey = this.textBox2.Text;
if(textBox2.Focused) //add this line in
int key = Convert.ToInt32(HexKey, 16);
}
【问题讨论】:
-
这段代码无法重现您的问题。这些函数调用中的任何一个都没有
startIndex参数。