- [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#] Hướng dẫn viết ứng dụng quay màn hình video winform, Screen Recorder
Xin chào các bạn, bài viết hôm nay mình sẻ hướng dẫn các bạn cách viết một ứng dụng nhỏ quay phim màn hình Desktop trên C#, Winform.
[C#] Video Recorder Winform

Đầu tiên, các bạn cần cài đặt thư viện ScreenRecorder từ thư viện Nuget Console:
PM> Install-Package ScreenRecorderLib -Version 3.1.1Giao diện demo ứng dụng Recorder Screen C#:

Full source phần mềm quay phim màn hình Desktop 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 ScreenRecorderLib;
namespace ScreenRecorder
{
    public partial class Form1 : Form
    {
        private Timer _progressTimer;
        private bool _isRecording;
        private int _secondsElapsed;
        Recorder _rec;
        public Form1()
        {
            InitializeComponent();
        }
        private void PauseButton_Click(object sender, EventArgs e)
        {
            if (_rec.Status == RecorderStatus.Paused)
            {
                _rec.Resume();
                return;
            }
            _rec.Pause();
        }
        private void RecordButton_Click(object sender, EventArgs e)
        {
            if (_isRecording)
            {
                _rec.Stop();
                _progressTimer?.Stop();
                _progressTimer = null;
                _secondsElapsed = 0;
                RecordButton.Enabled = false;
                return;
            }
            textBoxResult.Text = "";
            UpdateProgress();
            string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss");
            string videoPath = Path.Combine(Path.GetTempPath(), "ScreenRecorder", timestamp, timestamp + ".mp4");
   _progressTimer = new Timer();
            _progressTimer.Tick += _progressTimer_Tick;
            _progressTimer.Interval = 1000;
            _progressTimer.Start();
 _rec.Record(videoPath);
            _secondsElapsed = 0;
            _isRecording = true;
        }
        private void Rec_OnRecordingComplete(object sender, RecordingCompleteEventArgs e)
        {
            BeginInvoke(((Action)(() =>
            {
                string filePath = e.FilePath;
                textBoxResult.Text = filePath;
                PauseButton.Visible = false;
                RecordButton.Text = "Record";
                RecordButton.Enabled = true;
                this.labelStatus.Text = "Completed";
                _isRecording = false;
                CleanupResources();
            })));
        }
        private void Rec_OnRecordingFailed(object sender, RecordingFailedEventArgs e)
        {
            BeginInvoke(((Action)(() =>
            {
                PauseButton.Visible = false;
                RecordButton.Text = "Record";
                RecordButton.Enabled = true;
                labelStatus.Text = "Error:";
                labelError.Visible = true;
                labelError.Text = e.Error;
                _isRecording = false;
                CleanupResources();
            })));
        }
        private void _rec_OnStatusChanged(object sender, RecordingStatusEventArgs e)
        {
            BeginInvoke(((Action)(() =>
            {
                labelError.Visible = false;
                switch (e.Status)
                {
                    case RecorderStatus.Idle:
                        this.labelStatus.Text = "Idle";
                        break;
                    case RecorderStatus.Recording:
                        PauseButton.Visible = true;
                        if (_progressTimer != null)
                            _progressTimer.Enabled = true;
                        RecordButton.Text = "Stop";
                        PauseButton.Text = "Pause";
                        this.labelStatus.Text = "Recording";
                        break;
                    case RecorderStatus.Paused:
                        if (_progressTimer != null)
                            _progressTimer.Enabled = false;
                        PauseButton.Text = "Resume";
                        this.labelStatus.Text = "Paused";
                        break;
                    case RecorderStatus.Finishing:
                        PauseButton.Visible = false;
                        this.labelStatus.Text = "Finalizing video";
                        break;
                    default:
                        break;
                }
            })));
        }
        private void _rec_OnSnapshotSaved(object sender, SnapshotSavedEventArgs e)
        {
        }
        private void _progressTimer_Tick(object sender, EventArgs e)
        {
            _secondsElapsed++;
            UpdateProgress();
        }
        private void UpdateProgress()
        {
            labelTimestamp.Text = TimeSpan.FromSeconds(_secondsElapsed).ToString();
        }
        private void CleanupResources()
        {
            _progressTimer?.Stop();
            _progressTimer = null;
            _secondsElapsed = 0;
            _rec?.Dispose();
            _rec = null;
        }
        private void buttonOpenDirectory_Click(object sender, EventArgs e)
        {
            string directory = Path.Combine(Path.GetTempPath(), "ScreenRecorder");
            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            System.Diagnostics.Process.Start(directory);
        }
        private void buttonDeleteRecordedVideos_Click(object sender, EventArgs e)
        {
            try
            {
                Directory.Delete(Path.Combine(Path.GetTempPath(), "ScreenRecorder"), true);
                MessageBox.Show("Temp files deleted");
            }
            catch (Exception ex)
            {
                MessageBox.Show("An error occured while deleting files: " + ex.Message);
            }
        }
        private void buttonCopyPath_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(textBoxResult.Text))
            {
                Clipboard.SetText(textBoxResult.Text);
            }
        }
    }
}
Thanks for watching!

![[C#] Hướng dẫn viết ứng dụng quay màn hình video winform, Screen Recorder](https://laptrinhvb.net/uploads/users/9a8cb514e4428e85fb4ca07588e9103f.png)

![[C#] Làm việc với Microsoft PowerPoint file template trong Winform](https://laptrinhvb.net/uploads/source/csharp/power_point_thumb.png)
![[C#] Thay đổi Icon mặc định cho Folder trong lập trình Winform](https://laptrinhvb.net/uploads/source/csharp/icon_folder_csharp.png)

![[C#] Preprocessor Directives tiền xử lý trong lập trình csharp](https://laptrinhvb.net/uploads/source/csharp/preprocessor_thumb.png)
![[C#] Chia sẽ class SQLHelper sử dụng Dapper ORM trong lập trình Winform](https://laptrinhvb.net/uploads/source/csharp/dapper_orm_helper.png)
![[C#] Hướng dẫn tạo conner circle image trong PictureBox](https://laptrinhvb.net/uploads/source/image_baiviet/613ad6f17ba95c200a12826e9c2cdcaf.jpg)
![[C# - VB.NET] Hướng dẫn sử dụng Bing Translator API dịch các tiếng việt sang tiếng anh](https://laptrinhvb.net/uploads/source/image_baiviet/86527fd8629a528ede94e9c9ead7ce6b.jpg)
![[C#] Hướng dẫn convert Dataset to File Json trong lập trình Csharp](https://laptrinhvb.net/uploads/source/image_baiviet/98024d661064d26fe61689d55eb14bc8.jpg)
![[C#] Hướng dẫn chuyển đổi chuỗi sang nhị phân và ngược lại](https://laptrinhvb.net/uploads/source/image_baiviet/20c1faac8453ae1604adc8c2daf7d391.jpg)
![[C#] Hướng dẫn viết ứng dụng ngăn chặn tự động tắt màn hình máy tính khi không sử dụng](https://laptrinhvb.net/uploads/source/new_image_baiviet/disable_turn_off_monitor.png)
![[C#] Hướng dẫn thay đổi giao diện ứng dụng Winform theo giao diện của Windows](https://laptrinhvb.net/uploads/source/new_image_baiviet/CHANGE_THEME_THUMB.png)
![[C#] Tự động load user control vào form (Master layout C#)](https://laptrinhvb.net/uploads/source/image_baiviet/589c597b6aae2c9b9b821fdbd45fdac0.gif)
![[C#] Source code phần mềm Food Order sử dụng FlowLayoutPanel và Usercontrol](https://laptrinhvb.net/uploads/source/vbnet/dat_mon_thumb.jpg)
![[BÀI 1] Đơn giản hóa lập trình với cơ sở dữ liệu](https://laptrinhvb.net/uploads/source/image_baiviet/c7b293bfd050854c9ff4f5bc865649c4.jpg)
![[POWER AUTOMATE] Hướng dẫn gởi tin nhắn zalo từ file Excel - No code](https://laptrinhvb.net/uploads/source/new_image_baiviet/zalo_instance_csharp.png)
![[C#] Học lập trình linq với công cụ LINQPad](https://laptrinhvb.net/uploads/source/csharp/linqpad_thumb.png)
![[C#] Hướng dẫn Scan file hình ảnh trên máy scanner sử dụng WIA API](https://laptrinhvb.net/uploads/source/image_baiviet/c09991bd71d43786d784443b00e449b2.jpg)
![[C#] Hướng dẫn sử dụng temp mail service api trên winform](https://laptrinhvb.net/uploads/source/new_image_baiviet/temp_mail_service.png)
![[C#] Bắt lỗi sự kiện control sử dụng Error Provider trong lập trình csharp](https://laptrinhvb.net/uploads/source/image_baiviet/d84a548957738f58401d868f330ccb8c.gif)
![[C#] Giới thiệu thư viện Transition tạo hiệu ứng trên Winform](https://laptrinhvb.net/uploads/source/csharp/animation_csharp_thumb.gif)
![[C#] Hướng dẫn viết ứng dụng check live SSH Server](https://laptrinhvb.net/uploads/source/image_baiviet/6bc4d5b0ca4995dfce771849892f925e.jpg)
![[C#] Chặn chức năng chụp màn hình ứng dụng (print screen) trong winform](https://laptrinhvb.net/uploads/source/image_baiviet/b0fa0b8a886eb9a386cd88a9e9c5fcb8.jpg)
![[C#] Custom control PictureBox cho phép di chuyển trong Winform](https://laptrinhvb.net/uploads/source/csharp/MovePictureBoxInsideWinForm_thumb%20(1).jpg)
![[C#] Thiết kế giao diện Dark Mode UI cho winform](https://laptrinhvb.net/uploads/source/csharp/dark_form_csharp_thumb.jpg)
![[C#] Hướng dẫn đọc danh bạ Google sử dụng Google Contact API V3](https://laptrinhvb.net/uploads/source/csharp/google_contact_thumb.jpg)
