控件textBox4中不显示数据
Form1界面:public partial class Form1 : Form
{
string FName;
public Form1()
{
InitializeComponent();
}
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog1 = new OpenFileDialog();
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
FName = openFileDialog1.FileName;
Form2 newchild = new Form2(FName);
newchild.Show();
}
}
}
Form2界面:
public partial class Form2 : Form
{
Form1 tempForm = new Form1();
private string fName;
public Form2( string fname)
{
InitializeComponent();
this.fName = fname;
}
public void button1_Click(object sender, EventArgs e)
{
if (this.radioButton1.Checked)
{
File fileOpen = new File(fName);
tempForm.textBox4.Text = fileOpen.ReadFile();
tempForm.textBox4.AppendText("");
this.Close();
}
}
public class File
{
string fileName;
public File(string fileName)
{
this.fileName = fileName;
}
public string ReadFile()
{
try
{
StreamReader sr = new StreamReader(fileName, Encoding.Default);
string result = sr.ReadToEnd();
sr.ReadLine();
sr.Close();
return result;
}
catch (Exception e)
{
MessageBox.Show(e.Message);
return null;
}
}
}
程序执行后,Form1界面的控件textBox4不显示数据.为什么?