- [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
- Download và Giải nén tập tin File sử dụng Powershell
- [C#] Hướng dẫn cách lấy thông tin đăng nhập tài khoản và mật khẩu web browser trên windows
- [VB.NET] CRUD Thêm xóa sửa tìm kiếm Realtime FireBase
- [C#] Hiển thị thông báo Toast Message trong lập trình Winform
- [C#] Cấu hình định dạng ngày tháng, thời gian trên Windows cho ứng dụng Winform
- [C#] Rút gọn đường dẫn link url với TinyURL API
- [C#] Hướng dẫn cách bo tròn winform with Radius
- [C#] Chia sẽ class BackGroundOverlay Show Modal cho Winform
- [C#] Hướng dẫn Flip Image Winform
- [C#] Invoke là gì? cách sử dụng phương thức Invoke()
- [C#] Hướng dẫn chia sẽ file, folder từ ứng dụng sang Zalo Chat
[C#] Bắt sự kiện thay đổi clipboard windows
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ác bắt sự kiện thay đổi clipboard windows trong lập trình C# winform.
[C#] Trigger event changed clipboard windows
- Khi các bạn sử dụng tổ hợp phím
Ctrl + C
để copy một gì đó, thì chúng sẽ được đưa vào clipboard trong windows. - Trên windows 10, các bạn có thể bấm phím
Windows + V
để xem lịch sử clipboard
Ở bài này, mình sẽ sử dụng thư viện SharpClipboard để bắt sự kiện người dùng copy dữ liệu bất kỳ ở ứng dụng nào, thì tool của mình sẽ hiển thị ở đó.
Dưới đây là giao diện demo ứng dụng Clipboard C#:
Ở giao diện trên clipboard được chia là 3 loại chính: Text, Image và Link...
Ngoài ra thư viện còn support cho mình biết là mình copy vào clipboard từ ứng dụng nào trên Windows.
Full source code event changed clipboard 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;
using WK.Libraries.SharpClipboardNS;
namespace ClipboardChanged
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
chkMonitorClipboard.Checked = sharpClipboard1.MonitorClipboard;
chkObserveTexts.Checked = sharpClipboard1.ObservableFormats.Texts;
chkObserveFiles.Checked = sharpClipboard1.ObservableFormats.Files;
chkObserveImages.Checked = sharpClipboard1.ObservableFormats.Images;
}
private void sharpClipboard1_MonitorClipboardChanged(object sender, EventArgs e)
{
chkMonitorClipboard.Checked = sharpClipboard1.MonitorClipboard;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
sharpClipboard1.MonitorClipboard = chkMonitorClipboard.Checked;
}
private void chkObserveTexts_CheckedChanged(object sender, EventArgs e)
{
sharpClipboard1.ObservableFormats.Texts = chkObserveTexts.Checked;
}
private void chkObserveImages_CheckedChanged(object sender, EventArgs e)
{
sharpClipboard1.ObservableFormats.Images = chkObserveImages.Checked;
}
private void chkObserveFiles_CheckedChanged(object sender, EventArgs e)
{
sharpClipboard1.ObservableFormats.Files = chkObserveFiles.Checked;
}
private void sharpClipboard1_ClipboardChanged(object sender, SharpClipboard.ClipboardChangedEventArgs e)
{
if (e.ContentType == SharpClipboard.ContentTypes.Text)
{
txtCopiedTexts.Text = sharpClipboard1.ClipboardText;
}
else if (e.ContentType == SharpClipboard.ContentTypes.Image)
{
pbCopiedImage.Image = sharpClipboard1.ClipboardImage;
}
else if (e.ContentType == SharpClipboard.ContentTypes.Files)
{
List<string> files = new List<string>();
foreach (string file in sharpClipboard1.ClipboardFiles)
{
files.Add(Path.GetFileName(file));
}
Debug.WriteLine(sharpClipboard1.ClipboardFiles.ToArray());
lstCopiedFiles.Items.Clear();
lstCopiedFiles.Items.AddRange(files.ToArray());
}
else if (e.ContentType == SharpClipboard.ContentTypes.Other)
{
txtCopiedTexts.Text = sharpClipboard1.ClipboardText?.ToString();
}
textBox2.Text =
$"Name: {e.SourceApplication.Name} \n" +
$"Title: {e.SourceApplication.Title} \n" +
$"ID: {e.SourceApplication.ID} \n" +
$"Handle: {e.SourceApplication.Handle} \n" +
$"Path: {e.SourceApplication.Path}";
}
}
}
Thanks for watching!