- [POWER AUTOMATE] Hướng dẫn gởi tin nhắn zalo từ file Excel - No code
- [C#] Chia sẻ code lock và unlock user trong domain Window
- [SOFTWARE] Giới thiệu bộ phần mềm tính Kết Cấu Thép HatteSale, Mộng Đơn, Dầm, Sàn, Móng Cọc, Vách, Xà Gồ, Tính Tải Trọng
- [DEVEXPRESS] Vẽ Biểu Đồ Stock Chứng Khoán - Công Cụ Thiết Yếu Cho Nhà Đầu Tư trên Winform
- [C#] Hướng dẫn bảo mật ứng dụng 2FA (Multi-factor Authentication) trên Winform
- [C#] Hướng dẫn convert HTML code sang PDF File trên NetCore 7 Winform
- [C#] Hướng dẫn viết ứng dụng chat với Gemini AI Google Winform
- Hướng dẫn khóa file bằng nhiều process id, không cho xóa tập tin
- Hướng dẫn cách tạo Product Id cho ứng dụng phần mềm XXXXX-XXXXX-XXXXX-XXXXX
- [SQLSERVER] Hướng dẫn tạo script sql từ ứng dụng Sqlserver management Studio
- [C#] Hướng dẫn sử dụng thư viện AutoITx lấy id và password Ultraviewer trên winform
- [VB.NET] Hướng dẫn lấy thông tin tài khoản đăng nhập windows và khởi động lại ứng dụng ở chế độ Administrator
- [C#] Sử dụng thư viện Polly gửi lại request api khi request bị lỗi hay rớt mạng
- [DEVEXPRESS] Chia sẻ source code tạo báo cáo report in tem nhãn label trên C# winform
- [DEVEXPRESS] Hướng dẫn vẽ biểu đồ Bar Chart trên Winform
- [C#] Tạo form đăng nhập và đăng ký với hiệu ứng Sliding Animation Effect
- [C#] Hướng dẫn tạo thanh toán đơn hàng qua mã vạch VietQR sử dụng API PayOS hoàn toàn miễn phí
- [C#] Hướng dẫn ghi log ra RichTextBox giống Console trên Winform sử dụng thư viện Serilog
- [C#] Hướng dẫn cách tạo mã QR Code trên file Excel
- [VB.NET] Gởi tin nhắn và file đính kèm qua ứng dụng gởi tin nhắn Whats App
[C#] Thay đổi Icon mặc định cho Folder trong lập trình Winform
Xin chào các bạn, bài viết hôm nay mình sẽ tiếp tục hướng dẫn các bạn cách thay đổi hình ảnh Icon cho Folder của Window Explorer trong lập trình C# winform.
[C#] Change Icon Default folder Windows
Để thay đổi icon của một folder trong Windows, chúng ta sẽ sử dụng 1 file Desktop.ini, để thay đổi icon.
Cấu trúc file của Desktop.ini
thay đổi Icon như hình bên dưới:
[.ShellClassInfo]
ConfirmFileOp=True
NoSharing=True
IconFile=C:\Users\nguyenthao\Downloads\Hopstarter-Soft-Scraps-Email-Download.ico
IconIndex=0
IconFile là đường dẫn chỉ tới icon để thay đổi.
Giao diện demo ứng dụng thay đổi Icon Folder C#:
Full source code C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace SetIconFolder
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btn_selectFolder_Click(object sender, EventArgs e)
{
using (var fbd = new FolderBrowserDialog())
{
DialogResult result = fbd.ShowDialog();
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath))
{
txtFolderInput.Text = fbd.SelectedPath;
}
}
}
private void btn_SelectIcon_Click(object sender, EventArgs e)
{
using (var dlg = new OpenFileDialog())
{
DialogResult result = dlg.ShowDialog();
if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(dlg.FileName))
{
txtIconInput.Text = dlg.FileName;
pic_icon.LoadAsync(dlg.FileName);
}
}
}
private void btn_create_Click(object sender, EventArgs e)
{
var success = CreateIconedFolder(txtFolderInput.Text, txtIconInput.Text, 0, "", true, true);
if (success)
{
MessageBox.Show("Create Icon Successful!");
}
}
private bool CreateIconedFolder(string folderName, string iconFile, int iconIndex, string toolTip,
bool preventSharing, bool confirmDelete)
{
DirectoryInfo folder;
string fileName = "desktop.ini";
if (Directory.Exists(folderName) == false)
{
return false;
}
try
{
folder = new DirectoryInfo(folderName);
fileName = Path.Combine(folderName, fileName);
// Create the file
using (StreamWriter sw = new StreamWriter(fileName))
{
sw.WriteLine("[.ShellClassInfo]");
sw.WriteLine("ConfirmFileOp={0}", confirmDelete);
sw.WriteLine("NoSharing={0}", preventSharing);
sw.WriteLine("IconFile={0}", iconFile);
sw.WriteLine("IconIndex={0}", iconIndex);
sw.WriteLine("InfoTip={0}", toolTip);
sw.Close();
}
folder.Attributes = folder.Attributes | FileAttributes.System;
File.SetAttributes(fileName, File.GetAttributes(fileName) | FileAttributes.Hidden);
}
catch
{
return false;
}
return true;
}
private bool UndoIconedFolder(string folderName)
{
DirectoryInfo folder;
if (Directory.Exists(folderName) == false)
{
return false;
}
try
{
folder = new DirectoryInfo(folderName);
FileInfo file = new FileInfo(Path.Combine(folderName, "desktop.ini"));
if (file.Exists)
{
file.Delete();
}
folder.Attributes = (folder.Attributes | FileAttributes.System);
}
catch
{
return false;
}
return true;
}
private void btn_delete_Click(object sender, EventArgs e)
{
bool result = UndoIconedFolder(txtFolderInput.Text);
}
}
}
Sau khi chọn hình ảnh và thay đổi xong, các bạn nhé Restart lại Windows Explorer để xóa cache để hiển thị Icon cho folder.
Thanks for watching!