C# load file button label

隐身守侯 提交于 2019-12-13 02:19:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!