NEWS

[C#] Hiển thị hình ảnh GIF vào button, picturebox, label winform

[C#] Hiển thị hình ảnh GIF vào button, picturebox, label winform
Đăng bởi: Thảo Meo - Lượt xem: 15861 10:37:49, 07/01/2019DEVEXPRESS   In bài viết

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 Gifbutton, 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#:

gif_button_csharp

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");
            }
        }
    }
}

DOWNLOAD SOURCE

THÔNG TIN TÁC GIẢ

BÀI VIẾT LIÊN QUAN

[C#] Hiển thị hình ảnh GIF vào button, picturebox, label winform
Đăng bởi: Thảo Meo - Lượt xem: 15861 10:37:49, 07/01/2019DEVEXPRESS   In bài viết

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

Đọc tiếp
.