|
发表于 2019-5-11 18:43:14
|
显示全部楼层
山东省济南市
完成对TreeNode的右键菜单所有功能, 复制 删除 重命名 等...
private void TSMIRename_Click(object sender, EventArgs e)
{
if (tv.SelectedNode.Text == null) return;
tv.SelectedNode.BeginEdit();
}
private void TSMICopy_Click(object sender, EventArgs e)
{
if (tv.SelectedNode.Text == null) return;
Clipboard.SetText(tv.SelectedNode.Tag.ToString());
}
private void TSMIDelete_Click(object sender, EventArgs e)
{
if (tv.SelectedNode.Text == null) return;
MessageBox.Show(tv.SelectedNode.Tag.ToString(), "信息窗口");
if (File.Exists(tv.SelectedNode.Tag.ToString()))
{
File.Delete(tv.SelectedNode.Tag.ToString());
MessageBox.Show("ok", "信息窗口");
}
else
{
if (Directory.Exists(tv.SelectedNode.Tag.ToString()))
{
Directory.Delete(tv.SelectedNode.Tag.ToString(),true);
MessageBox.Show("ok", "信息窗口");
}
}
}
private void tv_KeyUp(object sender, KeyEventArgs e)
{
if (tv.SelectedNode.Text == null) return;
if (e.KeyValue == 113)
{
tv.SelectedNode.BeginEdit();
}
}
private void tv_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
{
if (string.IsNullOrWhiteSpace(e.Label)) return;
if (tv.SelectedNode.Text == null) return;
Console.WriteLine(e.ToString());
var item = e.Node;
DirectoryInfo dir = new DirectoryInfo(item.Tag.ToString());
string newPath = Path.Combine(dir.Parent.FullName, e.Label);
dir.MoveTo(newPath);
item.Tag = newPath;
} |
评分
-
查看全部评分
|