Winform 顯示Gif圖片的實例代碼
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.Diagnostics;
namespace DysncPicTest
{
public partial class Form1 : Form
{
private Image m_imgImage = null;
private EventHandler m_evthdlAnimator = null;
public Form1()
{
InitializeComponent();
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.DoubleBuffer, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true);
m_evthdlAnimator = new EventHandler(OnImageAnimate);
Debug.Assert(m_evthdlAnimator != null);
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if (m_imgImage != null)
{
UpdateImage();
e.Graphics.DrawImage(m_imgImage, new Rectangle(100, 100, m_imgImage.Width, m_imgImage.Height));
}
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
m_imgImage = Image.FromFile("1.gif"); // 加載測試用的Gif圖片
BeginAnimate();
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (m_imgImage != null)
{
StopAnimate();
m_imgImage = null;
}
}
private void BeginAnimate()
{
if (m_imgImage == null)
return;
if (ImageAnimator.CanAnimate(m_imgImage))
{
ImageAnimator.Animate(m_imgImage,m_evthdlAnimator);
}
}
private void StopAnimate()
{
if (m_imgImage == null)
return;
if (ImageAnimator.CanAnimate(m_imgImage))
{
ImageAnimator.StopAnimate(m_imgImage,m_evthdlAnimator);
}
}
private void UpdateImage()
{
if (m_imgImage == null)
return;
if (ImageAnimator.CanAnimate(m_imgImage))
{
ImageAnimator.UpdateFrames(m_imgImage);
}
}
private void OnImageAnimate(Object sender,EventArgs e)
{
this.Invalidate();
}
private void Form1_Load(object sender, EventArgs e)
{
}
}
}
- WinForm中實現(xiàn)picturebox自適應圖片大小的方法
- C# WinForm控件對透明圖片重疊時出現(xiàn)圖片不透明的簡單解決方法
- WinForm生成驗證碼圖片的方法
- C#實現(xiàn)winform中RichTextBox在指定光標位置插入圖片的方法
- Winform讓DataGridView左側(cè)顯示圖片
- Winform在DataGridView中顯示圖片
- winform 中顯示異步下載的圖片
- Winform實現(xiàn)將網(wǎng)頁生成圖片的方法
- Winform下實現(xiàn)圖片切換特效的方法
- 基于C# winform實現(xiàn)圖片上傳功能的方法
- winform壁紙工具為圖片添加當前月的日歷信息
- WinForm實現(xiàn)的圖片拖拽與縮放功能示例
相關文章
C#獲得MAC地址(網(wǎng)卡序列號)的實現(xiàn)代碼
這篇文章主要介紹了C#獲得MAC地址的實現(xiàn)代碼,需要的朋友可以參考下2014-02-02
基于使用遞歸推算指定位數(shù)的斐波那契數(shù)列值的解決方法
本篇文章介紹了,基于使用遞歸推算指定位數(shù)的斐波那契數(shù)列值的解決方法。需要的朋友參考下2013-05-05
C#調(diào)用C++動態(tài)庫接口函數(shù)和回調(diào)函數(shù)方法
這篇文章主要介紹了C#調(diào)用C++動態(tài)庫接口函數(shù)和回調(diào)函數(shù)方法,通過C++端編寫接口展開內(nèi)容,文章介紹詳細具有一定的參考價值,需要的小伙伴可以參考一下2022-03-03
淺析C#?AsyncLocal如何在異步間進行數(shù)據(jù)流轉(zhuǎn)
在異步編程中,處理異步操作之間的數(shù)據(jù)流轉(zhuǎn)是一個比較常用的操作,C#異步編程提供了一個強大的工具來解決這個問題,那就是AsyncLocal,下面我們就來看看AsyncLocal的原理和用法吧2023-08-08

