这个组件在Microsoft.VisualBasic中,可以直接调用这句话,然后提示会提醒你然后点击就可以添加这个命名空间了。
在WInform中使用的实例:
string str = Interaction.InputBox("请输入目标的名字", "重命名文件夹", "在这里输入", -1, -1);
str就可以得到文本框的输入的内容,Interaction.InputBox()中几个参数可以预置为以上,也可以自行调整
点击取消和X都是不会得到str的值的,可以用str.Length == 0来判断出本次操作无效,接着就可以通过拿到的参数来实现需要的功能了,这里实现了一个重命名。
private void 重命名ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (ControlFileClass.IsFolder(menupath))
{
string str = Interaction.InputBox("请输入目标的名字", "重命名文件夹", "在这里输入", -1, -1);
if (str.Length == 0)
{
MessageBox.Show("没有输入,无效操作");
return ;
}
Directory.SetCurrentDirectory(rootpath + @"\" + "txt");
Directory.Move(ControlFileClass.GetFileName(menupath), str);//使用filename但是get的是folder
Directory.SetCurrentDirectory(rootpath);
分区刷新(rootpath + @"\" + "txt"); ;
}
else
{
string str = Interaction.InputBox("请输入目标的名字", "重命名文件", "在这里输入,请注意需要同时输入后缀名", -1, -1);
if (str.Length == 0)
{
MessageBox.Show("没有输入,无效操作");
return;
}
string filename = ControlFileClass.GetFileName(menupath);
string foldername = ControlFileClass.GetFileName(ControlFileClass.GetFolderPath(menupath));
Directory.SetCurrentDirectory(rootpath + @"\" + "txt" + @"\" + foldername);
Directory.Move(filename, str);//使用filename但是get的是folder
Directory.SetCurrentDirectory(rootpath);
知识库刷新(fenquname);
}
}