- [DEVEXPRESS] Hỗ trợ tìm kiếm highlight không dấu và không khoảng cách trên Gridview Filter
- [C#] Chia sẻ source code phần mềm Image Downloader tải hàng loạt hình ảnh từ danh sách link url
- [C#] Chụp hình và quay video từ camera trên winform
- [C#] Chia sẽ full source code tách file Pdf thành nhiều file với các tùy chọn
- Giới thiệu về Stock Tracker Widget - Công cụ theo dõi cổ phiếu và cảnh báo giá tăng giảm bằng C# và WPF
- [VB.NET] Chia sẻ công cụ nhập số tiền tự động định dạng tiền tệ Việt Nam
- [VB.NET] Hướng dẫn fill dữ liệu từ winform vào Microsoft word
- [VB.NET] Hướng dẫn chọn nhiều dòng trên Datagridview
- Hướng Dẫn Đăng Nhập Nhiều Tài Khoản Zalo Trên Máy Tính Cực Kỳ Đơn Giản
- [C#] Chia sẻ source code phần mềm đếm số trang tập tin file PDF
- [C#] Cách Sử Dụng DeviceId trong C# Để Tạo Khóa Cho Ứng Dụng
- [SQLSERVER] Loại bỏ Restricted User trên database MSSQL
- [C#] Hướng dẫn tạo mã QRcode Style trên winform
- [C#] Hướng dẫn sử dụng temp mail service api trên winform
- [C#] Hướng dẫn tạo mã thanh toán VietQR Pay không sử dụng API trên winform
- [C#] Hướng Dẫn Tạo Windows Service Đơn Giản Bằng Topshelf
- [C#] Chia sẻ source code đọc dữ liệu từ Google Sheet trên winform
- [C#] Chia sẻ source code tạo mã QR MOMO đa năng Winform
- [C#] Chia sẻ source code phần mềm lên lịch tự động chạy ứng dụng Scheduler Task Winform
- [C#] Hướng dẫn download file từ Minio Server Winform
[C#] Tự động load user control vào form (Master layout C#)
Xin chào các bạn, bài viết này mình xin hướng dẫn các bạn sử dụng Dynamic load user control vào windows form C#. Hay có thể gọi đơn giản hơn là xây dựng Master layout C#.
Ví dụ: Khi các bạn viết một ứng dụng, mà chỉ có phần nội dung thay đổi, còn header, footer hay sidebar menu đều giống nhau.
Nếu các nào đã từng thiết kế web sẽ hiểu xây dựng master layout như thế nào.
Các bạn có thể xem demo ứng dụng:

Trong ví dụ này, Mình sẽ thiết kế ra một form chính frm_main, và 3 user control: uc_Module1.cs, uc_Module2.cs, uc_Module3.cs
Mỗi usercontrol tương ứng với một module nhé các bạn.
Khi các bạn xây dựng tách biệt ra từng user control, sẽ dễ dàng cho công việc quản lý source code.
Và có thể chia module ra cho từng thành viên code.
Dưới đây là source code form main:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LoadUserControlDynamic
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void Form1_Load(object sender, EventArgs e)
        {
        }
        private void btnModule1_Click(object sender, EventArgs e)
        {
            if (!panel.Controls.Contains(uc_Module1.Instance))
            {
                panel.Controls.Add(uc_Module1.Instance);
                uc_Module1.Instance.Dock = DockStyle.Fill;
                uc_Module1.Instance.BringToFront();
            }
            else
                uc_Module1.Instance.BringToFront();
        }
        private void btnModule2_Click(object sender, EventArgs e)
        {
            if (!panel.Controls.Contains(uc_Module2.Instance))
            {
                panel.Controls.Add(uc_Module2.Instance);
                uc_Module2.Instance.Dock = DockStyle.Fill;
                uc_Module2.Instance.BringToFront();
            }
            else
                uc_Module2.Instance.BringToFront();
        }
        private void btnModule3_Click(object sender, EventArgs e)
        {
            if (!panel.Controls.Contains(uc_Module3.Instance))
            {
                panel.Controls.Add(uc_Module3.Instance);
                uc_Module3.Instance.Dock = DockStyle.Fill;
                uc_Module3.Instance.BringToFront();
            }
            else
                uc_Module3.Instance.BringToFront();
        }
    }
}Source code cho uc_Module1.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LoadUserControlDynamic
{
    public partial class uc_Module1 : UserControl
    {
        private static uc_Module1 _instance;
        public static uc_Module1 Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new uc_Module1();
                return _instance;
            }
        }
        public uc_Module1()
        {
            InitializeComponent();
        }
        private void uc_Module1_Load(object sender, EventArgs e)
        {
        }
    }
}Source code cho uc_Module2.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LoadUserControlDynamic
{
    public partial class uc_Module2 : UserControl
    {
        private static uc_Module2 _instance;
        public static uc_Module2 Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new uc_Module2();
                return _instance;
            }
        }
        public uc_Module2()
        {
            InitializeComponent();
        }
        private void uc_Module2_Load(object sender, EventArgs e)
        {
        }
    }
}Source code cho uc_Module3.cs
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LoadUserControlDynamic
{
    public partial class uc_Module3 : UserControl
    {
        private static uc_Module3 _instance;
        public static uc_Module3 Instance
        {
            get
            {
                if (_instance == null)
                    _instance = new uc_Module3();
                return _instance;
            }
        }
        public uc_Module3()
        {
            InitializeComponent();
        }
        private void uc_Module3_Load(object sender, EventArgs e)
        {
        }
    }
}HAVE FUN :)

![[C#] Tự động load user control vào form (Master layout C#)](https://laptrinhvb.net/uploads/users/9a8cb514e4428e85fb4ca07588e9103f.png)

![[C#] Hướng dẫn in hóa đơn Invoice từ Template HTML và xuất ra file PDF](https://laptrinhvb.net/uploads/source/new_image_baiviet/screenshot_1663319839.png)
![[BUNIFU FRAMEWORK] Hướng dẫn viết ứng dụng đếm ngược thời gian (Count Down Timer) C#](https://laptrinhvb.net/uploads/source/image_baiviet/de7ea89752f88e36aa425f560dfd8f97.png)
![[C#] Sử dụng FolderBrowserDialog Vista trên Winform](https://laptrinhvb.net/uploads/source/new_image_baiviet/folder_brower_vista.png)
![[C#] Hướng dẫn tạo shortcut nhanh cho ứng dụng  đang chạy](https://laptrinhvb.net/uploads/source/csharp/short_cut_app_windows_thumb.png)
![[C#] Cấu hình định dạng ngày tháng, thời gian trên Windows cho ứng dụng Winform](https://laptrinhvb.net/uploads/source/csharp/set_date_time_format.png)
![[C#] Bảo mật phần mềm ứng dụng với thiết bị USB Serial Number](https://laptrinhvb.net/uploads/source/csharp/lock_app_usb_thumb.png)
![[C#] Hướng dẫn sử dụng từ khóa Params để truyền nhiều tham số vào hàm](https://laptrinhvb.net/uploads/source/csharp/params_csharp.png)
![[C#] Hướng dẫn tìm kiếm và set highlight color cho RichTextBox](https://laptrinhvb.net/uploads/source/image_baiviet/719506fede5d80228de36ef1b1d20110.jpg)
![[C#] Tạo hiệu ứng hình ảnh Image Cartoon Effect](https://laptrinhvb.net/uploads/source/csharp/effect_image_cartoon_thumb.png)
![[C#] Hướng dẫn lưu List Object thành tập tin file nhị phân Binary](https://laptrinhvb.net/uploads/source/devexpress/binary_file_thumb.png)
![[C#] Hướng dẫn tạo hiệu ứng Label Letter Text Effect](https://laptrinhvb.net/uploads/source/csharp/letter_text_effect.gif)
![[C#] Tra cứu mã số thuế cá nhân bằng CMND hoặc CCCD](https://laptrinhvb.net/uploads/source/vbnet/tracuu_mst_thumb.jpg)

![[C#] Viết ứng dụng get dữ liệu google suggest trong lap trinh csharp](https://laptrinhvb.net/uploads/source/image_baiviet/2ef41a883961b74f7e735053f1d41dad.png)
![[C#] Hướng dẫn push notification sử dụng Firebase Cloud Message](https://laptrinhvb.net/uploads/source/image_baiviet/a68bbcfbf9d22d60198c37eaeddbd5f1.jpg)
![[C#] Chia sẽ thư viện class làm việc với FTP SERVER bằng Csharp](https://laptrinhvb.net/uploads/source/new_image_baiviet/ftp_class.png)
![[C#] Download  Source code phần mềm tìm vị trí từ khóa google search (Keywords Tools C#)](https://laptrinhvb.net/uploads/source/image_baiviet/645d0adc84860b1ac5efb7f313956905.png)
![[C#] Hướng dẫn  sử dụng Regular Expression](https://laptrinhvb.net/uploads/source/image_baiviet/36e94c9623b615fa7218a4816e13c714.png)

![[C#] Hướng dẫn tạo menu trên Console App](https://laptrinhvb.net/uploads/source/new_image_baiviet/menu_console_csharp.gif)
![[C#] Chia sẽ source code Blur Login Form trên Winform](https://laptrinhvb.net/uploads/source/vbnet/blur_login_form.png)
![[C#] Viết ứng dụng Scan Subnet địa chỉ IP trong cùng mạng LAN](https://laptrinhvb.net/uploads/source/devexpress/scan_ip_thumb.jpg)
![[C#] Color Thief cách xuất màu sắc thiết kế từ hình ảnh](https://laptrinhvb.net/uploads/source/new_image_baiviet/pallet_color.png)
![[C#] Hướng dẫn DeCaptcha sử dụng thư viện Aforge.NET](https://laptrinhvb.net/uploads/source/image_baiviet/367c92283e4b7c4dabb331e3e9d4d527.png)
![[C#] Hướng dẫn tạo Form Splash Screen Good bye](https://laptrinhvb.net/uploads/source/csharp/good_bye_form.gif)
