0
我有一個代碼打開一個文件,並將其內容顯示到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");
}
不知道你在問什麼。你有文件名:'OpenFD.FileName'問題是標籤嗎? –
@RetiredNinja'OpenFD.FileName'返回正在讀取的文件的完整文件路徑。我認爲TS想要的只是文件名而不是完整的路徑。 – Hexxed
@Hexxed這可能是完全正確的,但它需要假設OP沒有給出的信息。 –