惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Google Online Security Blog
Google Online Security Blog
S
Security @ Cisco Blogs
Recent Commits to openclaw:main
Recent Commits to openclaw:main
人人都是产品经理
人人都是产品经理
The Hacker News
The Hacker News
W
WeLiveSecurity
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
The Cloudflare Blog
博客园 - 司徒正美
雷峰网
雷峰网
L
LINUX DO - 最新话题
博客园 - 叶小钗
云风的 BLOG
云风的 BLOG
The Last Watchdog
The Last Watchdog
V2EX - 技术
V2EX - 技术
S
Security Affairs
有赞技术团队
有赞技术团队
月光博客
月光博客
T
Threatpost
T
Tor Project blog
O
OpenAI News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
V
V2EX
Know Your Adversary
Know Your Adversary
Project Zero
Project Zero
博客园 - 三生石上(FineUI控件)
D
Docker
AWS News Blog
AWS News Blog
AI
AI
P
Proofpoint News Feed
K
Kaspersky official blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
D
Darknet – Hacking Tools, Hacker News & Cyber Security
www.infosecurity-magazine.com
www.infosecurity-magazine.com
S
Securelist
F
Fortinet All Blogs
F
Full Disclosure
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
量子位
Hacker News - Newest:
Hacker News - Newest: "LLM"
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
P
Palo Alto Networks Blog
Cyberwarzone
Cyberwarzone
Cisco Talos Blog
Cisco Talos Blog
美团技术团队
N
News | PayPal Newsroom
T
The Blog of Author Tim Ferriss
MyScale Blog
MyScale Blog

博客园 - 愚公

Bridges 虚拟化浪潮 MAGEUI的Hash问题 Lingoes的划词翻译功能极有可能泄露隐私 VSTO SaveCopyAs方法在Excel 2007下必须注意的一个问题 Vista Folders Always Shown In Details View - 让Vista文件夹总是使用详细资料视图 用7zip制作自动解压安装程序 安装新的Oracle Instant Client后重新配置PL/SQL Developer和环境: Certificates registry key name to MMC friendly name mapping A review of the CVS SCC PLUGIN IE8.0 TAB行为悄然改善: WSS 3.0 List WebService使用点滴 Set a password textbox for Visual Studio .NET setup project foobar2000绿色版在vista下的Unhandled exception: Bad allocation Virtual Server启动时自动启动每个虚机 NTFS文件及目录日期值行为 installState is missing ! .Net Framework 2.0配置工具Stopped Working VISTA BITS POLICY DESCRIPTION'S MISTAKE
在WinForm中控制GIF动画的启停的一种方法
愚公 · 2007-06-30 · via 博客园 - 愚公

    在WinForm中许多控件(本文以最常用的PictureBox为例)都有Image属性,如果该Image是一个动画Gif的话,它会自动运行动画。在某些场合,我们希望控制该动画的启停,此时我们首先想到了ImageAnimator,但实际使用时,我们发现以下指令根本不起作用,Gif停不下来,具体原因不明:

        ImageAnimator.StopAnimate(box.Image, new EventHandler(OnImageAnimate));
        
private void OnImageAnimate(Object sender, EventArgs e)
        
{
            
this.Invalidate();
        }

    此时,我想到控件的Enable属性,在其为false时,Gif是不会启动的,一旦设其为true,则动画立刻自动运行,因此只要该属性不作它用,则完全可以用来控制动画的启停。
    需要注意的是线程的安全性,以下代码示例实现了某一控件点击后启动Gif运行5秒钟,然后停下来:

        delegate void SetGifEnableCallback(Control control, bool enable);

        
void picboxSearching_Click(object sender, EventArgs e)
        
{
            Thread t 
= new Thread(new ThreadStart(Animate));
            t.Start();
        }


        
private void SetGifEnable(Control control, bool enable)
        
{
            
if (control.InvokeRequired)
            
{
                SetGifEnableCallback callback 
= new SetGifEnableCallback(SetGifEnable);
                
this.Invoke(callback, new object[] { control, enable });
            }

            
else control.Enabled = enable;
        }


        
private void Animate()
        
{
            PictureBox box 
= this.pictureBox1;
            AutoResetEvent waitHandler 
= new AutoResetEvent(false);
            SetGifEnable(box, 
true);
            waitHandler.WaitOne(
5000true);
            SetGifEnable(box, 
false);
        }