以下是我写的关于环境菜单(快捷菜单)里的具有“复制”,“粘贴”功能的实现代码,但是还不具备真正的复制粘贴功能,希望各位高手来给偶帮帮忙啊,
private void menuItemCopy_Click(object sender, System.EventArgs e)
{
try
{
if(CurPath.Count <1) return;
OriginFileName=FilesView.SelectedItems [0].Text;//记录源文件所在路径
OriginPath=CurPath[CurPath.Count -1]; //记录文件类型
if(FilesView.SelectedItems [0].ImageIndex ==1 || FilesView.SelectedItems [0].ImageIndex ==2)
{flag=1;}
else
{flag=0;}
canPaste=true;
CurPath.Add(OriginFileName);
MessageBox.Show (OriginPath+",\n"+OriginFileName);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void menuItemStick_Click(object sender, System.EventArgs e)
{
try
{
if(CurPath.Count<1)
return;
TargetPath=CurPath[CurPath.Count -1];//;//记录目标文件所在路径
//复制文件
if(flag==1) //是文件则复制
{
if(!File.Exists (TargetPath+"\\"+OriginFileName)) //目标路径不存在该文件
{
File.Copy (OriginPath+"\\"+OriginFileName,TargetPath+"\\"+OriginFileName);
MessageBox.Show (OriginPath+"\\"+OriginFileName+",\n"+TargetPath+"\\"+OriginFileName);
}
else
{
File.Copy (OriginPath+"\\"+OriginFileName,TargetPath+"\\"+OriginFileName+"复件");
MessageBox.Show (OriginPath+"\\"+OriginFileName+",\n"+TargetPath+"\\"+OriginFileName+"复件");
}
//更新目录
FillFilesView(TargetPath);//调函数
canPaste=false;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}