gpt4 book ai didi

c# - 流阅读器无法将文本从文件文本获取到文本框

转载 作者:行者123 更新时间:2023-11-30 15:16:00 26 4
gpt4 key购买 nike

try
{
Form frmShow = new Form();
TextBox txtShowAll = new TextBox();
frmShow.StartPosition = FormStartPosition.CenterScreen;
frmShow.Font = this.Font;
frmShow.Size = this.Size;
frmShow.Icon = this.Icon;
frmShow.Text = "All data";
txtShowAll.Dock = DockStyle.Fill;
txtShowAll.Multiline = true;
frmShow.Controls.Add(txtShowAll);
frmShow.ShowDialog();

StreamReader r = new StreamReader("empData.txt");
string strShowAllData = r.ReadToEnd();
txtShowAll.Text = strShowAllData;
r.Close();
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}

我确定文件名是正确的当我运行该程序时,它显示一个空文本框。

结果 enter image description here

最佳答案

我刚刚注意到您在以对话框模式显示表单后向文本框添加文本。你为什么不移动 frmShow.ShowDialog();到 try block 的末尾,就像我在下面的代码中所做的那样,并确保 empData.txt 存在于它的路径中。

        try
{
Form frmShow = new Form();
TextBox txtShowAll = new TextBox();
frmShow.StartPosition = FormStartPosition.CenterScreen;
frmShow.Font = this.Font;
frmShow.Size = this.Size;
frmShow.Icon = this.Icon;
frmShow.Text = "All data";
txtShowAll.Dock = DockStyle.Fill;
txtShowAll.Multiline = true;
frmShow.Controls.Add(txtShowAll);

StreamReader r = new StreamReader("empData.txt");
string strShowAllData = r.ReadToEnd();
txtShowAll.Text = strShowAllData;
r.Close();

frmShow.ShowDialog();
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}

关于c# - 流阅读器无法将文本从文件文本获取到文本框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50893397/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com