1

我想在 .NET 中使用 ListBox1.loadfromfile 方法,但它似乎不存在或具有与该方法等效的任何东西。我在 MSDN 图书馆网站上搜索过,但我空手而归。.NET 中是否有等效方法?

提前致谢,

4

2 回答 2

2

这可以让你接近:

listBox1.Items.AddRange(File.ReadAllLines(@"c:\test.txt"));
于 2012-05-01T19:44:20.413 回答
0

我不知道 .NET 中有什么可以模仿特定的 Delphi 构造。您可能必须手动将文本行加载到列表框中。这很简单:

// Read the file line by line
System.IO.StreamReader file = new System.IO.StreamReader(@"c:\somefile.txt");
while((line = file.ReadLine()) != null)
{
    //Add the line to the list box
    listBox1.Items.Add(line);
}

file.Close();
于 2012-05-01T19:29:55.190 回答