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"); // 加載測試用的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)圖片不透明的簡單解決方法
- WinForm生成驗(yàn)證碼圖片的方法
- C#實(shí)現(xiàn)winform中RichTextBox在指定光標(biāo)位置插入圖片的方法
- Winform讓DataGridView左側(cè)顯示圖片
- Winform在DataGridView中顯示圖片
- winform 中顯示異步下載的圖片
- Winform實(shí)現(xiàn)將網(wǎng)頁生成圖片的方法
- Winform下實(shí)現(xiàn)圖片切換特效的方法
- 基于C# winform實(shí)現(xiàn)圖片上傳功能的方法
- winform壁紙工具為圖片添加當(dāng)前月的日歷信息
- WinForm實(shí)現(xiàn)的圖片拖拽與縮放功能示例
相關(guān)文章
C#連接mysql數(shù)據(jù)庫完整實(shí)例
這篇文章主要介紹了C#連接mysql數(shù)據(jù)庫的方法,以一個(gè)完整實(shí)例形式分析了C#操作mysql數(shù)據(jù)庫連接的基本技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-05-05
C#如何從byte[]中直接讀取Structure實(shí)例詳解
這篇文章主要給大家介紹了關(guān)于利用C#如何從byte[]里直接讀取Structure的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-03-03
Winform窗口實(shí)現(xiàn)多顯示屏顯示的2種方法
這篇文章主要介紹了Winform窗口實(shí)現(xiàn)多顯示屏顯示的2種方法,本文直接給出了實(shí)現(xiàn)代碼,并對(duì)其中的一些重要參數(shù)做了解釋,需要的朋友可以參考下2015-06-06
C#中標(biāo)準(zhǔn)的IDispose模式代碼詳解
在本篇文章中小編給大家分享的是關(guān)于C#中標(biāo)準(zhǔn)的IDispose模式的實(shí)例用法相關(guān)內(nèi)容,有需要的朋友們測試下。2019-09-09
C#隨機(jī)設(shè)置900-1100毫秒延遲的方法
這篇文章主要介紹了C#隨機(jī)設(shè)置900-1100毫秒延遲的方法,涉及C#中Thread.Sleep方法的使用技巧,需要的朋友可以參考下2015-04-04
C#中的矩形數(shù)組(多維數(shù)組)和鋸齒數(shù)組的實(shí)現(xiàn)
本文主要介紹了C#中的矩形數(shù)組(多維數(shù)組)和鋸齒數(shù)組的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2023-04-04

