我在TextChanged事件處理程序中獲取文本框的Text值時遇到問題。無法從TextChanged事件處理程序中引用文本框的文本
我有以下代碼。 (簡體)
public float varfloat;
private void CreateForm()
{
TextBox textbox1 = new TextBox();
textbox1.Location = new Point(67, 17);
textbox1.Text = "12.75";
textbox1.TextChanged +=new EventHandler(textbox1_TextChanged);
}
private void textbox1_TextChanged(object sender, EventArgs e)
{
varfloat = float.Parse(textbox1.Text);
}
我得到以下錯誤:'名稱textbox1在當前上下文中不存在'。
我可能在某個地方犯了一個愚蠢的錯誤,但我是C#的新手,希望得到一些幫助。
在此先感謝!
很好的建議做了,謝謝。 –
不客氣。 – Adil