- Giới thiệu về Stock Tracker Widget - Công cụ theo dõi cổ phiếu 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
- GIỚI THIỆU TOOL: DUAL MESSENGER TOOLKIT
- [PHẦN MỀM] Giới thiệu Phần mềm Gmap Extractor
- 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
- [Phần mềm] Tải và cài đặt phần mềm Sublime Text 4180 full version
- [C#] Hướng dẫn download file từ Minio Server Winform
- [C#] Hướng dẫn đăng nhập zalo login sử dụng API v4 trên winform
[C#] Viết ứng dụng Auto Fill list Textbox from clipboard Winform
Xin chào các bạn, bài viết hôm nay mình tiếp tục hướng dẫn các bạn cách auto fill dữ liệu từ clipboard windows vào danh sách Textbox trên C#, winform.
[C#] Auto fill data from clipboard to list TextBox
Dưới đây, là hình ảnh demo ứng dụng:
Như hình trên, các bạn thấy ở trường dữ liệu nhập số căn cước công dân (CCCD).
Nó bao gồm 12 control Textbox như hình trên.
Khi chúng ta copy một dãy dữ liệu và kiểm tra nó đúng 12 số và không tồn tại ký tự đúng format của số căn cước công dân, thì chúng ta sẽ điền chúng vào tất cả Textbox trên.
Video demo ứng dụng:
Full source code C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FillFormClipboard
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
foreach (Control control in panel1.Controls)
{
if (control is TextBox)
{
TextBox textBox = (TextBox)control;
textBox.KeyDown += TextBox_KeyDown;
textBox.KeyPress += TextBox_KeyPress;
}
}
}
private void TextBox_KeyPress(object sender, KeyPressEventArgs e)
{
// chỉ cho phép nhập số
if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar))
{
e.Handled = true;
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void TextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.V)
{
HandlePasteEvent((TextBox)sender);
}
}
private void HandlePasteEvent(TextBox textBox)
{
if (Clipboard.ContainsText())
{
string clipboardText = Clipboard.GetText().Trim().Replace(" ","");
var regex = new Regex(@"^\d{12}$");
if (clipboardText.Length == 12 && regex.IsMatch(clipboardText))
{
char[] characters = clipboardText.ToCharArray();
foreach (Control control in panel1.Controls)
{
if (control is TextBox)
{
var nameControl = control.Name;
var i = Convert.ToInt16(nameControl.Split('_').LastOrDefault()) - 1;
control.Text = characters[i].ToString();
}
}
}
}
}
}
}
Thanks for watching!