- [C#] Bắt sự kiện bàn phím chuột bên ngoài ứng dụng winform sử dụng thư viện MouseKeyHook
- [DEVEXPRESS] Đặt mật khẩu và bỏ mật khẩu tập tin file PDF
- [C#] Thêm ứng dụng vào Taskbar sử dụng SharpShell DeskBand
- [C#] Hướng dẫn thêm text vào hình ảnh icon winform
- [C#] Chia sẽ tổng hợp source code đồ án về Csharp
- [C#] Hướng dẫn viết ứng dụng quay màn hình video winform, Screen Recorder
- [C#] Hướng dẫn sử dụng thư viện Input Simulator để làm việc với Keyboard, Mouse Virtual
- [DEVEXPRESS] Hướng dẫn tích Filter Contain khi click chuột phải vào cell selection trên Gridview
- [C#] Tra cứu mã số thuế cá nhân bằng CMND hoặc CCCD
- [C#] Convert hình ảnh image thành Blurhash sử dụng trong loading image winform
- [POWERSHELL] Script sao lưu backup và nén database sqlserver
- [C#] Giới thiệu thư viện Autofac Dependency Injection
- [C#] Hướng dẫn tạo Windows Services đơn giản Winform
- [C#] Một click chuột điều khiển máy tính từ xa sử dụng Ultraviewer
- Hướng dẫn đóng gói phần mềm sử dụng Powershell biên dịch script thành file exe
- [C#] Hướng dẫn sử dụng Task Dialog trên NET 5
- [C#] Hướng dẫn xem lịch sử các trang web đã truy cập trên Chrome Browser
- [C#] Hướng dẫn lấy thông tin Your ID và Password của Ultraviewer Winform
- [C#] Hướng dẫn lấy thông tin Your ID và Password của Teamviewer Winform
- [C#] Hướng dẫn build code động xuất file exe trên Winform
[C#] Hiển thị hình ảnh GIF vào button, picturebox, label winform
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 chèn hình Gif và button, picturebox, hay label trong winform lập trình C#.
Bạn có thể hiển thị hình Gif thông qua thuộc tính BackgroundImage trong từng button trên.
Và các bạn chỉnh lại vị trí của hình theo nhu cầu của mình: trái, giữa hay bên phải tùy bạn.
Dưới đây là giao diện demo Button Gif C#:
Source code Animation Button Gif C#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace howto_display_animated_gif
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
// Switch GIFs.
bool ButtonShowingPuppy = false;
private void btnGif_Click(object sender, EventArgs e)
{
ButtonShowingPuppy = !ButtonShowingPuppy;
if (ButtonShowingPuppy)
{
btnGif.Image = howto_display_animated_gif.Properties.Resources.puppy;
}
else
{
btnGif.Image = howto_display_animated_gif.Properties.Resources.under_construction;
}
}
// Switch GIFs, loading from files.
bool PictureBoxShowingPuppy = false;
private void picGif_Click(object sender, EventArgs e)
{
PictureBoxShowingPuppy = !PictureBoxShowingPuppy;
if (PictureBoxShowingPuppy)
{
picGif.Image = howto_display_animated_gif.Properties.Resources.puppy;
}
else
{
picGif.Image = howto_display_animated_gif.Properties.Resources.under_construction;
}
}
// Switch GIFs.
bool LabelShowingAlien = false;
private void lblGif_Click(object sender, EventArgs e)
{
string filename = Path.GetFullPath(
Path.Combine(Application.StartupPath, @"..\..\"));
LabelShowingAlien = !LabelShowingAlien;
if (LabelShowingAlien)
{
lblGif.Image = Image.FromFile(filename + "alien.gif");
}
else
{
lblGif.Image = Image.FromFile(filename + "under_construction.gif");
}
}
}
}