NEWS

[C#] Hướng dẫn tạo hiệu ứng text Fake Typer Effect Winform

[C#] Hướng dẫn tạo hiệu ứng text Fake Typer Effect Winform
Đăng bởi: Thảo Meo - Lượt xem: 3264 14:08:13, 05/02/2020DEVEXPRESS   In bài viết

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ách tạo hiệu ứng Auto Fake Typer Text Effect trong lập trình C# Winform.

Các bạn có thể sử dụng bài hướng dẫn này để làm cho form giới thiệu ứng dụng.

Hoặc dùng trong các form giống mấy form tạo key gen, hay tool auto...

Dưới đây là giao diện demo ứng dụng Auto Fake Typer Text Effect C# Winform:

autoTyper_demo

Source code C# Text Effect:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FakerType_TextEffect
{
    public partial class Form1 : Form
    {
        private char[] _chars;
        private int _index;
        public Form1()
        {
            InitializeComponent();
            _chars = richTextBox1.Text.ToCharArray();
        }

        private void richTextBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(_index< _chars.Length)
            {
                //richTextBox2.Text += _chars[_index];
                richTextBox2.AppendText(_chars[_index] + "");
                 _index++;

            }
                e.Handled = true;
        }
        bool flag = false;
        private void timer1_Tick(object sender, EventArgs e)
        {
            string a = "";
            if (_index < _chars.Length)
            {
                if(_index > 0)
                {
                    a = _chars[_index - 1].ToString();

                }               
                if(a == "
")
                {
                    flag = true;
                }
                else
                {
                    flag = false;
                }
                //richTextBox2.Text += _chars[_index];
                richTextBox2.AppendText(_chars[_index] + "");
                _index++;

            }
        }

        private void chk_auto_CheckedChanged(object sender, EventArgs e)
        {
            if (chk_auto.Checked)
            {
                richTextBox2.Clear();
                richTextBox2.Focus();
                timer1.Start();
                _index = 0;
            }
            else
            {
                timer1.Stop();
            }
        }

        private void richTextBox2_TextChanged(object sender, EventArgs e)
        {
            richTextBox2.SelectionStart = richTextBox2.Text.Length;
            if (!richTextBox2.ReachedBottom() && flag)
            {
                richTextBox2.ScrollToCaret();
            }
        }

    }
        public static  class RichTextBoxExtension
        {
            [DllImport("user32")]
            private static extern int GetScrollInfo(IntPtr hwnd, int nBar,
                                                    ref SCROLLINFO scrollInfo);

            public struct SCROLLINFO
            {
                public int cbSize;
                public int fMask;
                public int min;
                public int max;
                public int nPage;
                public int nPos;
                public int nTrackPos;
            }
            public static bool ReachedBottom(this RichTextBox rtb)
            {
                SCROLLINFO scrollInfo = new SCROLLINFO();
                scrollInfo.cbSize = Marshal.SizeOf(scrollInfo);
                //SIF_RANGE = 0x1, SIF_TRACKPOS = 0x10,  SIF_PAGE= 0x2
                scrollInfo.fMask = 0x10 | 0x1 | 0x2;
                GetScrollInfo(rtb.Handle, 1, ref scrollInfo);//nBar = 1 -> VScrollbar
                return scrollInfo.max == scrollInfo.nTrackPos + scrollInfo.nPage + 1;
            }
        }
}

Thanks for watching!

DOWNLOAD SOURCE

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

[C#] Hướng dẫn tạo hiệu ứng text Fake Typer Effect Winform
Đăng bởi: Thảo Meo - Lượt xem: 3264 14:08:13, 05/02/2020DEVEXPRESS   In bài viết

CÁC BÀI CÙNG CHỦ ĐỀ

Đọc tiếp
.