- [C#] Ẩn ứng dụng winform từ Apps vào Background Process trên Task Manager
- [SQLSERVER] Xử lý ngoại lệ sử dụng TRY...CATCH và RAISEERROR
- [C#] Bắt sự kiện bàn phím chuột bên ngoài ứng dụng winform sử dụng thư viện MouseKeyHook
- [DEVEXPRESS] Đặt mật khẩu và bỏ mật khẩu tập tin file PDF
- [C#] Thêm ứng dụng vào Taskbar sử dụng SharpShell DeskBand
- [C#] Hướng dẫn thêm text vào hình ảnh icon winform
- [C#] Chia sẽ tổng hợp source code đồ án về Csharp
- [C#] Hướng dẫn viết ứng dụng quay màn hình video winform, Screen Recorder
- [C#] Hướng dẫn sử dụng thư viện Input Simulator để làm việc với Keyboard, Mouse Virtual
- [DEVEXPRESS] Hướng dẫn tích Filter Contain khi click chuột phải vào cell selection trên Gridview
- [C#] Tra cứu mã số thuế cá nhân bằng CMND hoặc CCCD
- [C#] Convert hình ảnh image thành Blurhash sử dụng trong loading image winform
- [POWERSHELL] Script sao lưu backup và nén database sqlserver
- [C#] Giới thiệu thư viện Autofac Dependency Injection
- [C#] Hướng dẫn tạo Windows Services đơn giản Winform
- [C#] Một click chuột điều khiển máy tính từ xa sử dụng Ultraviewer
- Hướng dẫn đóng gói phần mềm sử dụng Powershell biên dịch script thành file exe
- [C#] Hướng dẫn sử dụng Task Dialog trên NET 5
- [C#] Hướng dẫn xem lịch sử các trang web đã truy cập trên Chrome Browser
- [C#] Hướng dẫn lấy thông tin Your ID và Password của Ultraviewer Winform
[DEVEXPRESS] Hướng dẫn sử dụng BreadCrumb Edit Control C#
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 sử dụng BreadCrumb Edit Control trong Devexpress C#.
Vậy BreadCrumb là gì?
Breadcrumb là một dạng thẻ điều hướng tập hợp nhiều liên kết (đường link) phân cấp, giúp cho người xem có thể biết được mình đang ở vị trí nào trên website. Breadcrumbs trong website thường được đặt ở vị trí đầu trang web, dưới banner chính, top headers và các thanh menu. Breadcrumb có cấu trúc như sau:
Trang chủ > Chuyên Mục (hoặc thẻ Tag) > Trang con
Trang chủ > Trang đã xem thứ nhất > Trang đã xem thứ hai > …
Breadcrumb các bạn thường thấy đa số được sử dụng trong thiết kế website, còn trong ứng dụng, các bạn dễ thấy nhất là đường dẫn thư mục của Windows Explorer.
Dưới đây là giao diện sử dụng Breadcrumb trong Devexpress C#:
Source code Breadcrumb Devexpress C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.Utils.Menu;
using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Repository;
namespace FileNavigator {
public partial class Form1 : XtraForm {
public static readonly int MaxEntitiesCount = 80;
public Form1() {
InitializeComponent();
Initialize();
}
void myItem_Click(object sender, EventArgs e) {
throw new NotImplementedException();
}
void Properties_QueryPopUp(object sender, CancelEventArgs e) {
throw new NotImplementedException();
}
//Set the Breadcrumb Editor's initial path
void Initialize() {
breadCrumbEdit1.Path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
foreach (DriveInfo driveInfo in GetFixedDrives()) {
breadCrumbEdit1.Properties.History.Add(new BreadCrumbHistoryItem(driveInfo.RootDirectory.ToString()));
}
}
private void breadCrumbEdit1_Properties_NewNodeAdding(object sender, DevExpress.XtraEditors.BreadCrumbNewNodeAddingEventArgs e) {
e.Node.PopulateOnDemand = true;
}
//Check whether or not the target path exists
private void breadCrumbEdit1_Properties_ValidatePath(object sender, DevExpress.XtraEditors.BreadCrumbValidatePathEventArgs e) {
if (!Directory.Exists(e.Path)) {
e.ValidationResult = DevExpress.XtraEditors.BreadCrumbValidatePathResult.Cancel;
return;
}
e.ValidationResult = DevExpress.XtraEditors.BreadCrumbValidatePathResult.CreateNodes;
}
private void breadCrumbEdit1_Properties_QueryChildNodes(object sender, DevExpress.XtraEditors.BreadCrumbQueryChildNodesEventArgs e) {
//Add custom shortcuts to the 'Root' node
if (string.Equals(e.Node.Caption, "Root", StringComparison.Ordinal)) {
InitBreadCrumbRootNode(e.Node);
return;
}
//Add local discs shortcuts to the 'Root' node
if (string.Equals(e.Node.Caption, "Computer", StringComparison.Ordinal)) {
InitBreadCrumbComputerNode(e.Node);
return;
}
//Populate dynamic nodes
string dir = e.Node.Path;
if (!Directory.Exists(dir))
return;
string[] subDirs = GetSubFolders(dir);
for (int i = 0; i < subDirs.Length; i++) {
e.Node.ChildNodes.Add(CreateNode(subDirs[i]));
}
}
void InitBreadCrumbRootNode(BreadCrumbNode node) {
node.ChildNodes.Add(new BreadCrumbNode("Desktop", Environment.GetFolderPath(Environment.SpecialFolder.Desktop)));
node.ChildNodes.Add(new BreadCrumbNode("Windows", Environment.GetFolderPath(Environment.SpecialFolder.Windows)));
node.ChildNodes.Add(new BreadCrumbNode("Program Files", Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)));
}
void InitBreadCrumbComputerNode(BreadCrumbNode node) {
foreach (DriveInfo driveInfo in GetFixedDrives()) {
node.ChildNodes.Add(new BreadCrumbNode(driveInfo.Name, driveInfo.RootDirectory));
}
}
protected BreadCrumbNode CreateNode(string path) {
string folderName = new DirectoryInfo(path).Name;
return new BreadCrumbNode(folderName, folderName, true);
}
//Get the local drives list
public static IEnumerable<DriveInfo> GetFixedDrives() {
foreach (DriveInfo driveInfo in DriveInfo.GetDrives()) {
if (driveInfo.DriveType != DriveType.Fixed) continue;
yield return driveInfo;
}
}
//Get all subfolders contained within the target directory
public static string[] GetSubFolders(string rootDir) {
string[] subDirs = GetSubDirs(rootDir);
if (subDirs == null)
return new string[0];
if (subDirs.Length <= MaxEntitiesCount)
return subDirs;
string[] res = new string[MaxEntitiesCount];
Array.Copy(subDirs, res, res.Length);
return res;
}
//Get the names of the subdirectories
public static string[] GetSubDirs(string dir) {
string[] subDirs = null;
try {
subDirs = Directory.GetDirectories(dir, "*", SearchOption.TopDirectoryOnly);
}
catch { }
return subDirs;
}
private void breadCrumbEdit1_PathChanged(object sender, BreadCrumbPathChangedEventArgs e) {
label2.Text = breadCrumbEdit1.Path;
}
private void breadCrumbEdit1_Properties_PathChanged(object sender, BreadCrumbPathChangedEventArgs e) {
}
}
}
Thanks for watching!