我有一个代码可以打开文件并将其内容显示到96个不同的文本框中。一行相当于一个文本框。我的问题是每当我打开文件时,我希望它的文件名显示在标签中我将如何能够做到这一点。这是我的代码
try
{
using (OpenFileDialog OpenFD = new OpenFileDialog()
{Filter = "Text Documents| *.txt", Multiselect = false,})
{
if(OpenFD.ShowDialog() == DialogResult.OK)
{
using(StreamReader Sr = new StreamReader(OpenFD.FileName))
{
MinArd1.Text = Sr.ReadLine();
MaxArd1.Text = Sr.ReadLine();
MinArd2.Text = Sr.ReadLine();
MaxArd2.Text = Sr.ReadLine();
MinArd3.Text = Sr.ReadLine();
MaxArd3.Text = Sr.ReadLine();
MinArd4.Text = Sr.ReadLine();
MaxArd4.Text = Sr.ReadLine();
MinArd5.Text = Sr.ReadLine();
MaxArd5.Text = Sr.ReadLine();
MinArd6.Text = Sr.ReadLine();
MaxArd6.Text = Sr.ReadLine();
MinArd7.Text = Sr.ReadLine();
MaxArd7.Text = Sr.ReadLine();
MinArd8.Text = Sr.ReadLine();
MaxArd8.Text = Sr.ReadLine();
MinArd9.Text = Sr.ReadLine();
MaxArd9.Text = Sr.ReadLine();
MinArd10.Text = Sr.ReadLine();
MaxArd10.Text = Sr.ReadLine();
MinArd11.Text = Sr.ReadLine();
MaxArd11.Text = Sr.ReadLine();
MinArd12.Text = Sr.ReadLine();
MaxArd12.Text = Sr.ReadLine();
MinArd13.Text = Sr.ReadLine();
MaxArd13.Text = Sr.ReadLine();
MinArd14.Text = Sr.ReadLine();
MaxArd14.Text = Sr.ReadLine();
MinArd15.Text = Sr.ReadLine();
MaxArd15.Text = Sr.ReadLine();
MinArd16.Text = Sr.ReadLine();
MaxArd16.Text = Sr.ReadLine();
MinArd17.Text = Sr.ReadLine();
MaxArd17.Text = Sr.ReadLine();
MinArd18.Text = Sr.ReadLine();
MaxArd18.Text = Sr.ReadLine();
MinArd19.Text = Sr.ReadLine();
MaxArd19.Text = Sr.ReadLine();
MinArd20.Text = Sr.ReadLine();
MaxArd20.Text = Sr.ReadLine();
MinArd21.Text = Sr.ReadLine();
MaxArd21.Text = Sr.ReadLine();
MinArd22.Text = Sr.ReadLine();
MaxArd22.Text = Sr.ReadLine();
MinArd23.Text = Sr.ReadLine();
MaxArd23.Text = Sr.ReadLine();
MinArd24.Text = Sr.ReadLine();
MaxArd24.Text = Sr.ReadLine();
MinArd25.Text = Sr.ReadLine();
MaxArd25.Text = Sr.ReadLine();
MinArd26.Text = Sr.ReadLine();
MaxArd26.Text = Sr.ReadLine();
MinArd27.Text = Sr.ReadLine();
MaxArd27.Text = Sr.ReadLine();
MinArd28.Text = Sr.ReadLine();
MaxArd28.Text = Sr.ReadLine();
MinArd29.Text = Sr.ReadLine();
MaxArd29.Text = Sr.ReadLine();
MinArd30.Text = Sr.ReadLine();
MaxArd30.Text = Sr.ReadLine();
MinArd31.Text = Sr.ReadLine();
MaxArd31.Text = Sr.ReadLine();
MinArd32.Text = Sr.ReadLine();
MaxArd32.Text = Sr.ReadLine();
MinArd33.Text = Sr.ReadLine();
MaxArd33.Text = Sr.ReadLine();
MinArd34.Text = Sr.ReadLine();
MaxArd34.Text = Sr.ReadLine();
MinArd35.Text = Sr.ReadLine();
MaxArd35.Text = Sr.ReadLine();
MinArd36.Text = Sr.ReadLine();
MaxArd36.Text = Sr.ReadLine();
MinArd37.Text = Sr.ReadLine();
MaxArd37.Text = Sr.ReadLine();
MinArd38.Text = Sr.ReadLine();
MaxArd38.Text = Sr.ReadLine();
MinArd39.Text = Sr.ReadLine();
MaxArd39.Text = Sr.ReadLine();
MinArd40.Text = Sr.ReadLine();
MaxArd40.Text = Sr.ReadLine();
MinArd41.Text = Sr.ReadLine();
MaxArd41.Text = Sr.ReadLine();
MinArd42.Text = Sr.ReadLine();
MaxArd42.Text = Sr.ReadLine();
MinArd43.Text = Sr.ReadLine();
MaxArd43.Text = Sr.ReadLine();
MinArd44.Text = Sr.ReadLine();
MaxArd44.Text = Sr.ReadLine();
MinArd45.Text = Sr.ReadLine();
MaxArd45.Text = Sr.ReadLine();
MinArd46.Text = Sr.ReadLine();
MaxArd46.Text = Sr.ReadLine();
MinArd47.Text = Sr.ReadLine();
MaxArd47.Text = Sr.ReadLine();
MinArd48.Text = Sr.ReadLine();
MaxArd48.Text = Sr.ReadLine();
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("mali");
}
答案 0 :(得分:0)
试试这个。如果您只想获取文件名,因为OpenFD.FileName
返回文件的完整文件路径
myLabel.Text = Path.GetFileName(OpenFD.FileName);