前期准备
txt文件(含内容)C#窗体(含textbox)
textbox属性设置
首先将textbox扩大,即不仅仅是只显示一行,而是显示多行的状态。
在"行为"一栏中,将"Multiline" 的属性设置为True: ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200328021409286.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjU4MjI0MQ==,size_16,color_FFFFFF,t_70)
其次设置textbox为可上下左右翻阅的功能。
在"外观"一栏中,将"ScrollBars" 的属性设置为Both: 若想设置为只读模式,则需要在“行为”一栏中,将“ReadOnly”的属性设置为True: 若不想显示光标(只读模式下),则在“行为”一栏中,将“Enabled”的属性设置为False: ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200328025553269.png)
cs代码
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace email
{
public partial class pop3 : Form
{
public pop3()
{
InitializeComponent();
ReadTextFile(@"C:\pop3.txt"); //文本所在位置
}
private void ReadTextFile(string filePath) //文本展示
{
string[] lines = File.ReadAllLines(filePath);
foreach(string line in lines)
{
textBox1.AppendText(line + Environment.NewLine);
}
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
}
private void label4_Click(object sender, EventArgs e) //返回
{
}
}
}
运行结果
显示光标: 不显示光标: ![在这里插入图片描述](https://img-blog.csdnimg.cn/20200328025305458.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl80MjU4MjI0MQ==,size_16,color_FFFFFF,t_70)
|