- [C#] Viết ứng dụng xem và dò kết quả xổ số kiến thiết miền nam
- [C#] Hướng dẫn viết ứng dụng theo dõi máy in bao nhiêu trang (Monitor Printer)
- [C#] Lấy thông tin cấu hình máy tính xuất ra text file winform
- [C#] Chia sẽ class Install, Uninstall, Start và Stop Services Winform
- [C#] Tìm kiếm tập tin file nhanh chóng trên Winform sử dụng thư viện FastSearchLibrary
- [C#] Giới thiệu thư viện Fluent FTP Awesome dùng để làm việc với FTP
- [C#] Sử dụng thư viện Mini Profiler Integrations ghi log thực hiện các câu lệnh SQL
- [DEVEXPRESS] Thiết kế Dropdown ButtonBarItem trên Form Ribbon
- [C#] Lưu trạng thái các control trên Winform vào Registry Windows
- [C#] Ứng dụng ví dụ Simple Observer Pattern tăng giảm số lượng trên winform
- [C#] Hướng dẫn lấy thời gian thực server time trên winform
- [DEVEXPRESS] Hướng dẫn bật tính năng Scroll Pixcel in Touch trên GridView
- [DEVEXPRESS] Hướng dẫn sử dụng TileBar viết ứng dụng duyệt hình ảnh Winform
- [DEVEXPRESS] Tô màu border TextEdit trên Winform
- [C#] Lấy dữ liệu từ Console Write hiển thị lên textbox Winform
- [C#] Hiển thị Progress bar trên Window Console
- [C#] Di chuyển control Runtime và lưu layout trên winform
- [SQLSERVER] Sử dụng hàm NULL IF
- [C#] Chia sẽ source code mã đi tuần bằng giao diện Winform
- [C#] Flash Window in Taskbar Winform
[DEVEXPRESS] Hướng dẫn thiết kế Form Setting Tùy chọn trong 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 thiết kế và tạo form setting tùy chọn trong lập trình C# sử dụng TreeView và Load usercontrol Dynamic.
[DEVEPRESS] DESIGN SETTING FORM C#
Trong lập trình ứng dụng, các bạn thường thấy sẽ có một form để chứa các thông tin tham số của hệ thống.
Ví dụ: ứng dụng lập trình Visual Studio
Các bạn vào Tools => Options => sẽ xuất hiện hộp thoại cho các bạn cấu hình các thông tin chung của Editor: font, color, theme, wordwrap, num Line...
Các bạn thấy hình trên sẽ có hai Panel:
Một panel bên trái chức TreeView chứa các danh sách menu
và một panel bên phải để load các usercontrol tùy chỉnh vào theo treeview menu bên trái.
Dưới đây là giao diện demo Setting Form C#:
Source code chương trình C#:
using OptionsDemoTree.UserControl;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace OptionsDemoTree
{
public partial class Form1 : DevExpress.XtraEditors.XtraForm
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
treeList1.DataSource = InitData();
treeList1.ParentFieldName = "ParentID";
treeList1.KeyFieldName = "ID";
treeList1.TreeViewFieldName = "Name";
treeList1.ExpandAll();
}
public DataTable InitData()
{
DataTable table = new DataTable();
table.Columns.Add("ParentID", typeof(int));
table.Columns.Add("Code", typeof(string));
table.Columns.Add("Name", typeof(string));
table.Columns.Add("ID", typeof(int));
table.Columns.Add("Image_Index", typeof(int));
table.Rows.Add(0,"NS", "Nhân Sự", 1, 0);
table.Rows.Add(1,"NC", "Ngày công", 4, 3);
table.Rows.Add(2,"TC", "Tăng ca", 5, 3);
table.Rows.Add(1,"NNP", "Nghĩ phép năm", 6, 3);
table.Rows.Add(0,"KT", "Kế Toán", 2, 1);
table.Rows.Add(2,"NHT", "Năm hoạch toán", 7, 3);
table.Rows.Add(2,"DK", "Định khoản", 8, 3);
table.Rows.Add(0,"CDC", "Cài đặt chung", 3, 2);
return table;
}
private void treeList1_AfterFocusNode(object sender, DevExpress.XtraTreeList.NodeEventArgs e)
{
var dataRow = treeList1.GetDataRow(e.Node.Id);
var codeName = dataRow.ItemArray[1] + "";
if(codeName == "NNP")
{
if (!panMain.Controls.Contains(uControl2.Instance))
{
panMain.Controls.Add(uControl2.Instance);
uControl2.Instance.Dock = DockStyle.Fill;
uControl2.Instance.BringToFront();
}
else
uControl2.Instance.BringToFront();
}else if(codeName == "NC")
{
if (!panMain.Controls.Contains(uControl3.Instance))
{
panMain.Controls.Add(uControl3.Instance);
uControl3.Instance.Dock = DockStyle.Fill;
uControl3.Instance.BringToFront();
}
else
uControl3.Instance.BringToFront();
}
}
private void treeList1_GetStateImage(object sender, DevExpress.XtraTreeList.GetStateImageEventArgs e)
{
try
{
int index = int.Parse(e.Node.GetValue("Image_Index").ToString());
if (index >= 0)
{
e.NodeImageIndex = index;
}
}
catch (Exception) { }
}
}
}
Thanks for watching!