- [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#] Hướng dẫn tạo Float Text OSD Windows trong lập trình Winform
Xin chào các bạn, bài viết hôm nay mình sẽ chia sẽ đến các bạn source code cách tạo Float Text OSD Windows trên Winform lập trình C#.
[C#] Hướng dẫn tạo Float Text OSD Windows trong lập trình Winform
Mấy hôm trước, bên IT của công ty mình có cài một phần mềm với tên BgInfo, phần mềm này giúp chúng ta hiển thị các thông tin cấu hình ra màn hình Desktop.
Các thông tin như: RAM, CPU, HDD, Network, OS,...
Và mình thấy rất hay, không biết trên C# thì cách chúng ta thực hiện như thế nào, thế là mình lang thang trên Internet và kiếm được source code OSD Windows rất hay của tác giả Mr.Smarty.
Giao diện demo ứng dụng:
Và dưới đây là source code C# tạo OSD windows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MrSmarty.CodeProject
{
public partial class Demo : Form
{
private FloatingOSDWindow[] _osd = new FloatingOSDWindow[4];
private Point[] _pnt = new Point[4];
private byte[] _alpha = new byte[4];
private Color[] _textColor = new Color[4];
private Font[] _textFont = new Font[4];
private int[] _textTime = new int[4];
private FloatingWindow.AnimateMode[] _mode = new FloatingWindow.AnimateMode[4];
private uint[] _animateTime = new uint[4];
private string[] _text = new string[4];
private Rectangle _rScreen = Screen.PrimaryScreen.Bounds;
public Demo()
{
InitializeComponent();
this._numX.Maximum = this._rScreen.Width;
this._numY.Maximum = this._rScreen.Height;
//--OSD windows
for(int i = 0; i < this._osd.Length; i++)
this._osd[i] = new FloatingOSDWindow();
//--OSD start point
this._pnt[0] = new Point(20, 45); this._pnt[1] = new Point(this._rScreen.Width / 8, this._rScreen.Height / 2);
this._pnt[2] = new Point(this._rScreen.Width / 6, this._rScreen.Height / 2 - this._rScreen.Height / 4); this._pnt[3] = new Point(100, this._rScreen.Height / 2 - this._rScreen.Height / 8);
//--OSD transparency
this._alpha[0] = 120; this._alpha[1] = 231; this._alpha[2] = 90; this._alpha[3] = 122;
//--OSD text color
this._textColor[0] = Color.Lime; this._textColor[1] = Color.DarkCyan; this._textColor[2] = Color.RoyalBlue; this._textColor[3] = Color.DarkMagenta;
//--OSD text font
this._textFont[0] = new Font("Arial", 22f, FontStyle.Bold); this._textFont[1] = new Font("Microsoft Sans Serif", 28f, FontStyle.Regular);
this._textFont[2] = new Font("Courier New", 36f, FontStyle.Bold | FontStyle.Underline); this._textFont[3] = new Font("Verdana", 26f, FontStyle.Bold | FontStyle.Italic);
//--OSD text time
this._textTime[0] = 3000; this._textTime[1] = 1800; this._textTime[2] = 3900; this._textTime[3] = 2400;
//--OSD window animation effect
this._mode[0] = FloatingWindow.AnimateMode.ExpandCollapse; this._mode[1] = FloatingWindow.AnimateMode.Blend;
this._mode[2] = FloatingWindow.AnimateMode.SlideLeftToRight; this._mode[3] = FloatingWindow.AnimateMode.RollRightToLeft;
//--OSD animate time
this._animateTime[0] = 200; this._animateTime[1] = 0; this._animateTime[2] = 0; this._animateTime[3] = 370;
//--OSD text
this._text[0] = this._txtText.Text; this._text[1] = "Hello! I am a Memember of Laptrinhvb.net";
this._text[2] = "Chào mừng ngày quốc khánh Việt Nam 02/09/2019!"; this._text[3] = "Tôi Yêu Việt Nam!";
//defaults for custom OSD
this._numX.Value = this._pnt[0].X; this._numY.Value = this._pnt[0].Y;
this._numAlpha.Value = this._alpha[0]; this._numTextTime.Value = this._textTime[0];
this._numAnimateTime.Value = this._animateTime[0];
this._lbSample.ForeColor = this._textColor[0]; this._lbSample.Font = this._textFont[0];
this._cbAnimate.Items.AddRange(Enum.GetNames(typeof(FloatingWindow.AnimateMode)));
this._cbAnimate.SelectedIndex = (int)this._mode[0];
}
private void demo_KeyDown(object sender, KeyEventArgs e)
{
if(e.KeyCode == Keys.Escape)
this.Close();
}
private void _all_Click(object sender, EventArgs e)
{
int idx;
switch((sender as Button).Tag.ToString())
{
case "1": idx = 1; break;
case "2": idx = 2; break;
case "3": idx = 3; break;
default: idx = 0; break;
}
if(idx == 0)
{
this._pnt[0] = new Point((int)this._numX.Value, (int)this._numY.Value);
this._alpha[0] = (byte)this._numAlpha.Value;
this._textColor[0] = this._lbSample.ForeColor;
this._textFont[0] = this._lbSample.Font;
this._textTime[0] = (int)this._numTextTime.Value;
this._mode[0] = (FloatingWindow.AnimateMode)this._cbAnimate.SelectedIndex;
this._animateTime[0] = (uint)this._numAnimateTime.Value;
this._text[0] = this._txtText.Text;
}
this._osd[idx].Show(this._pnt[idx], this._alpha[idx], this._textColor[idx], this._textFont[idx], this._textTime[idx],
this._mode[idx], this._animateTime[idx], this._text[idx]);
}
private void _bColorPick_Click(object sender, EventArgs e)
{
this._dlgColor.Color = this._lbSample.ForeColor;
if(this._dlgColor.ShowDialog()==DialogResult.OK)
this._lbSample.ForeColor = this._dlgColor.Color;
}
private void _bFontPick_Click(object sender, EventArgs e)
{
this._dlgFont.Font = this._lbSample.Font;
if(this._dlgFont.ShowDialog() == DialogResult.OK)
this._lbSample.Font = this._dlgFont.Font;
}
}
}
Video demo ứng dụng OSD C#:
Thanks for watching!