开发者

Displaying Data on the Windows Form

开发者 https://www.devze.com 2022-12-25 08:27 出处:网络
I\'m searching files and r开发者_JAVA百科eturning lines that include the search text, and I\'m not really sure the best way to display the information I get. Every time I get a match, I want to show,

I'm searching files and r开发者_JAVA百科eturning lines that include the search text, and I'm not really sure the best way to display the information I get. Every time I get a match, I want to show, in some sort of control, the File it came from, and the whole text line. (aka streamreader.ReadLine() result). First I tried just putting it all in a read-only text box, but it doesn't have a scroll bar.

What is the best form control to help me display this data neatly?


The text box should do just fine. Just set MultiLine to true and ScrollBars to Auto (or Vertical, whichever suits you best).


Your best bet would probably be either a Listbox, or a DataGridView.

Also maybe have a look at Environment.NewLine Property


A ListView will work for this. Set its View property to Details, and add two columns in the designer (call them FileName and FirstLine or something, and play around with the widths as you like).

You add a new line like this:

string FileName = @"c:\file1.txt";
string FirstLine = "This is the first line of text from the file";
ListViewItem item = new ListViewItem(FileName);
item.SubItems.Add(FirstLine);
listView1.Items.Add(item);


You could use a list box to list the files in which the text was found, and then, a text box containing the text you want to show. You should be able to work if you do like Fredrik Mörk said.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号