从我了解你之后,你要通过的文件在一个特定的目录遍历,然后让他们进行编辑与一次在列表框中双击打开。
这可以通过使用var Files = Directory.GetFiles("path", ".txt");
Files
将文件名的string[]
来完成。
ListBox lbx = new ListBox();
lbx.Size = new System.Drawing.Size(X,Y); //Set to desired Size.
lbx.Location = new System.Drawing.Point(X,Y); //Set to desired Location.
this.Controls.Add(listBox1); //Add to the window control list.
lbx.DoubleClick += OpenFileandBeginEditingDelegate;
lbx.BeginUpdate();
for(int i = 0; i < numfiles; i++)
lbx.Items.Add(Files[i]);
lbx.EndUpdate();
现在你的事件委托应该是这个样子:
OpenFileandBeginEditingDelegate(object sender, EventArgs e)
{
string file = lbx.SelectedItem.ToString();
FileStream fs = new FileStream(Path + file, FileMode.Open);
//Now add this to the textbox
byte[] b = new byte[1024];
UTF8Encoding temp = new UTF8Encoding(true);
while (fs.Read(b,0,b.Length) > 0)
{
tbx.Text += temp.GetString(b);//tbx being the textbox you want to use as the editor.
}
}
我们通过VS编辑窗口添加事件处理程序
然后用这些文件是这样的填充列表框点击相关控件并转到该控件的属性窗格。您将需要切换到事件窗格并滚动,直到找到DoubleClick
事件,如果您使用该设计器应该自动插入有效的委托签名并允许您为该事件编写逻辑。
这很简单,列出ListBox或ListView中文件夹中的所有文本文件并处理MouseDoubleClick来读取内容并将其显示在TextBox中,那么问题是什么? – Bolu 2013-05-11 21:07:31