C#加载文件按钮标签 [英] C# load file button label

查看:62
本文介绍了C#加载文件按钮标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用richTextBox1.LoadFile(open.FileName, RichTextBoxStreamType.PlainText); 将文件加载到文本框中.

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

我正在使用C#和Visual Studio 2010 Express

I'm using C# and Visual Studio 2010 express

推荐答案

以下是一些让您入门的东西:

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++;
     }

 }

这篇关于C#加载文件按钮标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆