C#一段代码

来源:百度知道 编辑:UC知道 时间:2024/06/19 16:05:26
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace texttest
{
public partial class Form1 : Form
{
List<string> alist = new List<string>();
int times = 0;
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)
{
times = 0;
alist.Clear();
string line;
StreamReader sr = new StreamReader("a.txt", Encoding.Default);
while ((line = sr.ReadLine()) != null)
{
alist.Add(line);
}
timer1.Interval = 1000;
timer1.Enabled = true;

给他焦点他自己就是最新的一行

在加载之后;List<string> alist = new List<string>();
是不是已经存储一定的值
你要想在第一行显示文本中最后一行的话
很简单,
可以直接使用:Text1.Text = alist[alist.Length-1] + "\r\n";
保存到文本框中不就可以了。