C#列表框双击事件和文件的操作

来源:百度知道 编辑:UC知道 时间:2024/06/22 06:30:30
我现在有一个列表框,显示了一个文件夹里的所有文件(例"f:\恐龙园")。我现在想双击列表框中一个文件后,这个文件就从这个文件夹移动到另一个文件夹(例“f:\常州”)。
各位高手帮帮忙,刚接触C#,想学习下。列表框ID是 _ListBox文件列表
3楼的代码看不懂啊~

你查一下IO流操作文件

using System.IO;

在列表的双击事件里写

用File.Move(olderPath, newPath);

private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
{
string strPath = "";
string strNewDir="";
if (this.listBox1.Items.Count > 0)
{
for (int i = 0; i < this.listBox1.Items.Count; i++)
{
this.listBox1.SetSelected(i, false);
if (this.listBox1.GetItemRectangle(0).Contains(e.Location))
{
this.listBox1.SetSelected(i,true);
strPath =this.listBox1.SelectedValue.ToString();
if (File.Exists(strPath))
{
File.Move(strPath, strNewDir + Path.GetFileName(strPath));
}