سلام
در فرم یک دکمه Read داریم می خوام با کلیم بر روی آن با استفاده از openFileDialog مسیر یک فایل متنی رو بدم و محتوای فایل متنی در TextBox نمایش داده بشه.
این فرم من هست :
Untitled.png
این کدهای فایل کلاس :
namespace read_write
{
public class Class1
{
public void read(string r)
{
OpenFileDialog op = new OpenFileDialog();
op.ShowDialog();
StreamReader sr = new StreamReader(op.FileName);
sr.ReadToEnd();
sr.Close();
}
}
}
این کدهای دکمه :
private void button1_Click(object sender, EventArgs e)
{
string reading;
reading = textBox1.Text;
Class1 red = new Class1();
red.read(reading);
}
برنامه خطایی نداره اما کار هم نمیکنه.
تشکر