-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathForm2.cs
60 lines (58 loc) · 1.78 KB
/
Form2.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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 taskManagement
{
public partial class Form2 : Form
{
private static Form2 f;
public static Form2 GetSingle()
{
if (f == null || f.IsDisposed)
{
f = new Form2();
}
return f;
}
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
//读入目录树
string path = @"../data/";
this.listView.Items.Clear();
string[] files = Directory.GetFiles(path);
ListViewItem item = new ListViewItem();
foreach (string file in files)
{
item = new ListViewItem();
item.Text = Path.GetFileName(file);
item.Tag = Path.GetFullPath(file);
this.listView.Items.Add(item);
}
}
private void listView_SelectedIndexChanged(object sender, EventArgs e)
{
//查看内容
if (this.listView.SelectedItems.Count > 0)
{
string path = this.listView.FocusedItem.Tag.ToString();
using (FileStream stream = new FileStream(path, FileMode.Open))
{
byte[] buffer = new byte[1024 * 10];
stream.Read(buffer, 0, buffer.Length);
this.label1.Text = Encoding.Default.GetString(buffer);
}
}
}
}
}