问题
I'm using richTextBox1.LoadFile(open.FileName, RichTextBoxStreamType.PlainText);
to load a file in a textbox.
What I want to do is to load a file line by line and each line to be the label of a button in such a way to have multiple buttons each with each line from file
I'm using C# and Visual Studio 2010 express
回答1:
Here is something to start you off:
private void Form1_Load(object sender, EventArgs e)
{
int i = 1;
var allLines = File.ReadAllLines(@"c:\temp\test.txt");
foreach (var line in allLines)
{
var b = new Button();
b.Text = line;
b.AutoSize = true;
b.Location = new Point(0, b.Size.Height * i);
this.Controls.Add(b);
i++;
}
}
来源:https://stackoverflow.com/questions/5945942/c-sharp-load-file-button-label