我正在尝试为文本文件的每一行动态创建一个新按钮。文本文件每行的新按钮?
我的问题是无论文本文件有多少行,它只生成一个按钮。
代码:
System.IO.StreamReader file = new System.IO.StreamReader
(@"D:\SupportDash\Settings\Settings.txt");
string[] lines = System.IO.File.ReadAllLines(@"D:\SupportDash\Settings\Settings.txt");
foreach(String row in lines)
{
Button Buttona = new System.Windows.Forms.Button();
Buttona.Text = "Test";
Buttona.UseVisualStyleBackColor = true;
Buttona.Location = new System.Drawing.Point(85,28);
Buttona.Click += (s, e) =>
{
Form DynamicForm = new Form();
DynamicForm.Show();
};
groupBox2.Controls.Add(Button);
counter++;
}
file.Close();
}
我也用了一段时间,一个do-while循环尝试。 - 同样的事情发生。
我的文本文件由回车分隔。 (它使用File.ApendAllText()生成在程序中)
难道是我的程序引起的一个问题,只是认为有一条巨大的线?
太棒了,我不知道为什么我认为它会为我做。谢谢。 – Wills