¿Toda la instancia 11? ¿Aún no creas un proyecto? ¿No sabes los pasos? ¿No puedes escribir código? ¡Visite el siguiente enlace para aprender!
1. Puntos de conocimiento
2. Diseño de estilo
Seleccione los siguientes controles en la herramienta
3. Implementación del código
using System.Windows.Forms;
using System.IO;
namespace 文件管理
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
StartPosition = FormStartPosition.CenterScreen;
}
//”删除”的Click事件的代码
private void button1_Click(object sender, EventArgs e)
{
string dpath = textBox1.Text;
if (dpath != "")
{
if (File.Exists(@dpath)) //如果路径下存在文件
{
File.Delete(@dpath);
MessageBox.Show(@dpath + "删除成功!");
}
else
{ MessageBox.Show("文件不存在!"); }
}
else
{
MessageBox.Show("请输入要删除的文件!");
textBox1.Focus();
}
}
//”复制”的Click事件的代码
private void button2_Click(object sender, EventArgs e)
{
string srcpath = textBox2.Text;
string destpath = textBox3.Text;
if (srcpath == "" || destpath == "")
MessageBox.Show("请输入要复制的源文件与目的文件路径!");
else
{
if (File.Exists(@srcpath))
{
File.Copy(@srcpath, @destpath);
MessageBox.Show(@srcpath + "复制到" + @destpath + "成功!");
}
else
{ MessageBox.Show("源文件不存在!"); }
}
}
//”移动”的Click事件的代码
private void button3_Click(object sender, EventArgs e)
{
string srcpath = textBox4.Text;
string destpath = textBox5.Text;
if (srcpath == "" || destpath == "")
MessageBox.Show("请输入要移动的源文件与目的文件路径!");
else
{
if (File.Exists(@srcpath))
{
File.Move(@srcpath, @destpath);
MessageBox.Show(@srcpath + "移动到" + @destpath + "成功!");
}
else
{ MessageBox.Show("源文件不存在!"); }
}
}
//”获取信息”的Click事件的代码
private void button4_Click(object sender, EventArgs e)
{
string detailpath = textBox6.Text;
richTextBox1.Clear();
if (File.Exists(@detailpath))
{
FileInfo fi = new FileInfo(@detailpath);
if ((fi.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden)
richTextBox1.AppendText("文件属性:隐藏文件\n");
else
richTextBox1.AppendText("文件属性:不是隐藏文件\n");
richTextBox1.AppendText("文件建立时间:" + fi.CreationTime + '\n');
richTextBox1.AppendText("文件最后修改时间:" + fi.LastWriteTime + '\n');
richTextBox1.AppendText("文件长度:" + fi.Length + '\n');
}
else
MessageBox.Show("文件不存在!");
}
}
}