- [C#] Hướng dẫn convert HTML code sang PDF File trên NetCore 7 Winform
- [C#] Hướng dẫn viết ứng dụng chat với Gemini AI Google Winform
- Hướng dẫn khóa file bằng nhiều process id, không cho xóa tập tin
- Hướng dẫn cách tạo Product Id cho ứng dụng phần mềm XXXXX-XXXXX-XXXXX-XXXXX
- [SQLSERVER] Hướng dẫn tạo script sql từ ứng dụng Sqlserver management Studio
- [C#] Hướng dẫn sử dụng thư viện AutoITx lấy id và password Ultraviewer trên winform
- [VB.NET] Hướng dẫn lấy thông tin tài khoản đăng nhập windows và khởi động lại ứng dụng ở chế độ Administrator
- [C#] Sử dụng thư viện Polly gửi lại request api khi request bị lỗi hay rớt mạng
- [DEVEXPRESS] Chia sẻ source code tạo báo cáo report in tem nhãn label trên C# winform
- [DEVEXPRESS] Hướng dẫn vẽ biểu đồ Bar Chart trên Winform
- [C#] Tạo form đăng nhập và đăng ký với hiệu ứng Sliding Animation Effect
- [C#] Hướng dẫn tạo thanh toán đơn hàng qua mã vạch VietQR sử dụng API PayOS hoàn toàn miễn phí
- [C#] Hướng dẫn ghi log ra RichTextBox giống Console trên Winform sử dụng thư viện Serilog
- [C#] Hướng dẫn cách tạo mã QR Code trên file Excel
- [VB.NET] Gởi tin nhắn và file đính kèm qua ứng dụng gởi tin nhắn Whats App
- [C#] Viết ứng dụng Auto Fill list Textbox from clipboard Winform
- [TOOL] Chia sẻ phần mềm thay đổi thông tin cấu hình máy tính
- [C#] Hướng dẫn Export dữ liệu ra file Microsoft Word Template
- [C#] Chia sẻ source code tool kiểm tra domain website
- [C#] Hướng dẫn tạo file PDF sử dụng thư viện QuestPDF
[C#] Hướng dẫn tạo hiệu ứng Decode Text Effect Label
Xin chào các bạn, bài viết hôm nay mình sẽ chia sẽ cho các bạn một component Decode Text Label C#, giúp các bạn tạo hiệu ứng như các website đã bị hacker.
Trong đoạn code các bạn cần tạo một component, thừa kế từ lớp Label để chúng ta override lớp này lại.
Sử dụng Timer, các hàm substring để tạo hiệu ứng cho Text Label.
Dưới đây, là giao diện demo ứng dụng Decode Text Label Effect C#:
Ở hình trên, các bạn nhìn thấy trông rất cool phải không các bạn.
Đầu tiên, các bạn tạo cho mình một class component DecodeLabel.cs
Source code C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DecodeTextEffect
{
public partial class DecodeLabel : Label
{
private readonly Timer _timerAnimate = new Timer();
private TextDecodeEffect _decodeEffect;
private bool _showing;
private int _initGenCount;
public int Interval
{
get { return _timerAnimate.Interval; }
set { _timerAnimate.Interval = value; }
}
public DecodeLabel()
{
_timerAnimate.Interval = 100;
_timerAnimate.Tick += _timerAnimate_Tick;
}
public void Animate(bool show, string text, int initGenCount)
{
_initGenCount = initGenCount;
_decodeEffect = new TextDecodeEffect(text) { TextVisible = !show };
Text = _decodeEffect.Peek(DecodeMode.None);
_showing = show;
_timerAnimate.Start();
}
private void _timerAnimate_Tick(object sender, EventArgs e)
{
if(_initGenCount != 0)
{
Text = _decodeEffect.GenerateNumberRange(Text.Length);
_initGenCount--;
return;
}
var decodeMode = _showing ? DecodeMode.Show : DecodeMode.Hide;
var text = _decodeEffect.Peek(decodeMode);
if(text == null)
{
_timerAnimate.Stop();
}
else
{
Text = text;
}
}
}
public enum DecodeMode
{
None,
Show,
Numbers,
Hide
}
class TextDecodeEffect
{
private int _visiableCount;
private readonly Random _random = new Random();
public bool TextVisible
{
get { return _visiableCount == OriginalText.Length; }
set { _visiableCount = value ? OriginalText.Length : 0; }
}
public string OriginalText { get; private set; }
public TextDecodeEffect(string text)
{
OriginalText = text;
}
public string Peek(DecodeMode mode)
{
switch (mode)
{
case DecodeMode.Numbers:
return GenerateNumberRange(OriginalText.Length);
case DecodeMode.Hide:
if (_visiableCount == 0) return null;
_visiableCount--;
break;
case DecodeMode.Show:
if(_visiableCount == OriginalText.Length)
{
return null;
}
_visiableCount++;
break;
}
var text = GenerateNumberRange(OriginalText.Length - _visiableCount);
text += OriginalText.Substring(OriginalText.Length - _visiableCount, _visiableCount);
return text;
}
public string GenerateNumberRange(int count)
{
var SB = new StringBuilder();
for (int i = 0; i < count; i++)
SB.Append(_random.Next(0, 10));
return SB.ToString();
}
}
}
Sau khi các bạn tạo xong class này, các bạn build ứng dụng lên, và sau đó, các bạn nhìn vào thanh Toolbox sẽ có một component mới với tên Decodelabel, từ thanh công cụ, các bạn kéo
component này vào winform để sử dụng.
Sau khi các bạn kéo component này ra, các bạn set cho nó các thuộc tính sau:
AutoSize = false
TextAlign = MiddleCenter
Set font chữ cho nó size khoảng 35.
Background = Black
Forecolor = Lime
Các bạn, có thể download source của mình để sử dụng font chữ OCR Extend, font chữ như ứng dụng mình demo ở trên.
Trong form1.cs, các bạn viết sự kiện khi click vào Decode Label thì chạy hiệu ứng.
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.Threading.Tasks;
using System.Windows.Forms;
namespace DecodeTextEffect
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void decodeLabel1_Click(object sender, EventArgs e)
{
decodeLabel1.Animate(true, "Website is hacked by laptrinhvb.net!", 5);
}
}
}
HAVE FUN :)