每當我嘗試清除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'參數。 –