Hướng dẫn cách ẩn và hiện các thư mục trong winform
Đầu tiên các bạn thiết kế giao diện ứng dụng như hình bên dưới:
=> Sau đó, các bạn có thể chọn thao tác Hide và Unhide để ẩn hay hiển thị thư mục folder trên windows.
Source code C# Hide, Unhide Folder:
C#:
using System;
using System.IO;
using System.Windows.Forms;
namespace HideFolder
{
public partial class Form1 : Form
{
DirectoryInfo ch;
public Form1()
{
InitializeComponent();
}
private void btnBrowse_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
txtFilePath.Text = folderBrowserDialog1.SelectedPath;
}
}
private void btnOpen_Click(object sender, EventArgs e)
{
try
{
System.Diagnostics.Process.Start(txtFilePath.Text);
}
catch { }
}
private void btnHide_Click(object sender, EventArgs e)
{
try
{
ch = new DirectoryInfo(txtFilePath.Text);
ch.Attributes = FileAttributes.Hidden;
MessageBox.Show("Hidden");
}
catch { }
}
private void btnUnhide_Click(object sender, EventArgs e)
{
try
{
ch = new DirectoryInfo(txtFilePath.Text);
ch.Attributes = FileAttributes.Normal;
MessageBox.Show("Visible");
}
catch { }
}
}
}
kết quả: