本文介绍了如何写入文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在一次读取一行文本文件并尝试解析并提取值,然后将其写入文本框。在一个简单的教程中,我可以写入文本框。
这个工作...
I'm reading a text file one line at a time and trying to parse and extract a value then write it to a text box. In a simple tutorial I can write to the textbox.
this works...
private void button1_Click(object sender, EventArgs e)
{
textBox1.Text = "My test";
txbSysColors.Text = "";
}
private void button2_Click(object sender, EventArgs e)
{
txbSysColors.Text = "System Colors";
textBox1.Text = "";
}
我尝试过:
当我添加条件语句时,即使在引号之间传递文字字符串,我也无法再写文本框。我看到str的内容,包含的数据是正确的。
所有文本框保持空白运行此代码。
What I have tried:
When I add conditional statements I can no longer write the text boxes even passing a literal string between quotes. I see the contents of "str" and the data contained is correct.
all the text boxes remain blank running this code.
private void button1_Click(object sender, EventArgs e)
{
openFileDialog1.ShowDialog();
StreamReader stream = new StreamReader(openFileDialog1.FileName);
string str = "";
while ((str = stream.ReadLine()) != null)
{
if (str.Contains("SYS_CLR"))
{
txbSysColors.Text = str.Split('=').Last().ToString();
txbSysColors.Text = "here";
textBox1.Text = "here";
textBox1.Text = str;
}
}
}
是否有一些范围问题我不理解?
Is there some scope issue I'm not understanding?
推荐答案
这篇关于如何写入文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!