Winform 顯示Gif圖片的實(shí)例代碼
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"); // 加載測(cè)試用的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中實(shí)現(xiàn)picturebox自適應(yīng)圖片大小的方法
- C# WinForm控件對(duì)透明圖片重疊時(shí)出現(xiàn)圖片不透明的簡(jiǎn)單解決方法
- WinForm生成驗(yàn)證碼圖片的方法
- C#實(shí)現(xiàn)winform中RichTextBox在指定光標(biāo)位置插入圖片的方法
- Winform讓DataGridView左側(cè)顯示圖片
- Winform在DataGridView中顯示圖片
- winform 中顯示異步下載的圖片
- Winform實(shí)現(xiàn)將網(wǎng)頁(yè)生成圖片的方法
- Winform下實(shí)現(xiàn)圖片切換特效的方法
- 基于C# winform實(shí)現(xiàn)圖片上傳功能的方法
- winform壁紙工具為圖片添加當(dāng)前月的日歷信息
- WinForm實(shí)現(xiàn)的圖片拖拽與縮放功能示例
相關(guān)文章
C#獲得MAC地址(網(wǎng)卡序列號(hào))的實(shí)現(xiàn)代碼
這篇文章主要介紹了C#獲得MAC地址的實(shí)現(xiàn)代碼,需要的朋友可以參考下2014-02-02基于使用遞歸推算指定位數(shù)的斐波那契數(shù)列值的解決方法
本篇文章介紹了,基于使用遞歸推算指定位數(shù)的斐波那契數(shù)列值的解決方法。需要的朋友參考下2013-05-05C#調(diào)用C++動(dòng)態(tài)庫(kù)接口函數(shù)和回調(diào)函數(shù)方法
這篇文章主要介紹了C#調(diào)用C++動(dòng)態(tài)庫(kù)接口函數(shù)和回調(diào)函數(shù)方法,通過(guò)C++端編寫接口展開內(nèi)容,文章介紹詳細(xì)具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-03-03淺析C#?AsyncLocal如何在異步間進(jìn)行數(shù)據(jù)流轉(zhuǎn)
在異步編程中,處理異步操作之間的數(shù)據(jù)流轉(zhuǎn)是一個(gè)比較常用的操作,C#異步編程提供了一個(gè)強(qiáng)大的工具來(lái)解決這個(gè)問(wèn)題,那就是AsyncLocal,下面我們就來(lái)看看AsyncLocal的原理和用法吧2023-08-08c# 面試必備線程基礎(chǔ)知識(shí)點(diǎn)
這篇文章主要介紹了c# 面試必備線程基礎(chǔ)知識(shí)點(diǎn),幫助大家更好的鞏固,掌握線程的基礎(chǔ)知識(shí),感興趣的朋友可以了解下2020-11-11基于C#動(dòng)態(tài)生成帶參數(shù)的小程序二維碼
在微信小程序管理后臺(tái),我們可以生成下載標(biāo)準(zhǔn)的小程序二維碼,提供主程序入口功能,在實(shí)際應(yīng)用開發(fā)中,小程序二維碼是可以攜帶參數(shù)的,可以動(dòng)態(tài)進(jìn)行生成,本文小編就給大家介紹一下如何基于C#動(dòng)態(tài)生成帶參數(shù)的小程序二維碼,感興趣的朋友可以參考下2023-12-12利用AOP實(shí)現(xiàn)SqlSugar自動(dòng)事務(wù)
這篇文章主要為大家詳細(xì)介紹了利用AOP實(shí)現(xiàn)SqlSugar自動(dòng)事務(wù),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10