[C#] Hiển thị hình ảnh GIF vào button, picturebox, label winform
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");
}
}
}
}
Chúc các bạn thành công.


Comments
THỦ THUẬT HAY GIÚP CHO MỌI NGƯỜI THIẾT KẾ VÀ TẠO CHO ỨNG DỤNG CÓ NÉT KHÁC BIỆT RIÊNG CỦA TỪNG NGƯỜI NHÉ :d
ReplyDeletea cho e hỏi, làm thế nào để chỉnh sữa cho vừa với khung dữ liệu vậy?
ReplyDeletetuỳ chỉnh tho hình ảnh bản nhé.
Delete