如何显示文本文件数据

问题描述:

我目前正在开发一个gui应用程序,一旦用户指定了要加载的文件名,该应用程序就应该在gui窗口上显示文本文件内容.
问题是,我不知道使用哪种工具查看文件内容,因此任何人都可以帮忙吗?我已经用谷歌搜索了,但没有找到任何直接答案.

Hi, i am currently developing a gui application that is supposed to display text file content on the gui window once the user has specified the name of the file to load.
the problem is, i do not know which tool is used to view file content so can anyone help on that? i have googled this and i did not find any direct answer.

在您的表单上放置一个文本框.将TextBox名称设置为适当的名称,并将MultiLine属性设置为True.
然后,当用户指定要加载的文件时,将文本加载到字符串数组中,并将TextBox Lines属性设置为字符串数组.
Put a TextBox on your form. Set the TextBox name to something sensible, and set the MultiLine property to True.
Then, when your user specifies the file to load, load the text into an array of strings, and set the TextBox Lines property to the array of strings.
string[] lines = File.ReadAllLines(@"D:\Temp\MyLargeTextFile.txt");
myTextBox.Lines = lines;


问题还不是很清楚,但是您可能想检查一下这些控件.
文本框 [ ^ ]
RichTextBox [
Well your question is not completely clear but you may want to check out these controls.
TextBox[^]
RichTextBox[^]

there are examples at the bottom of the pages.

See Solution 2 for an example of how to load a file into a multiple line TextBox.