C#列表框双击事件和文件的操作
来源:百度知道 编辑:UC知道 时间:2024/06/22 06:30:30
各位高手帮帮忙,刚接触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));
}