Animated GIF on WinForm: Go

Source: Internet
Author: User

WinForm on the ProgressBar, honestly, it is not flattering, too rigid, too ugly, even if made real-time display processing progress, it still can not escape the "ugly." Now the web2.0 everywhere can see a show is working on the small circle in that turn ah turn, to indicate that is processing, although it is not real-time, just a GIF animation, but its effect is always felt than the WinForm on the ProgressBar to be more pleasing. Can I use this GIF animation to show progress on my WinForm? The answer is obviously, yes, I heard PictureBox can display GIF animation, as long as the image property of the control is set to what we mean by GIF animation can be, compile, run, oh, GIF animation strike, it simply does not move, just stay in a frame. It seems that this way of taking shortcuts in the IT industry is not feasible.

Then we still use the Imageanimator.animate () method, found that the language organization is not up, or with direct look at the code to quickly, more and more feel sad .... Words are not clear ...

First, define the private variable the m_img=null;private EventHandler evthandler=null;//overloads of the current WinForm OnPaint method, When the interface is redrawn, the current GIF is displayed to display a frame protected override void OnPaint (PaintEventArgs e) {base.    OnPaint (e);        if (m_image! = null) {//Gets the current GIF animation next to render the frame.        UpdateImage ();        The frame that you want to render for the current GIF animation is displayed in a location on the interface.    E.graphics.drawimage (M_image, New Rectangle (145,, M_image.width, m_image.height));    }}//implement the Load method private load (object Sender,eventargs e) {//For a delegate to associate a processing method evthandler=new EventHandler (onimageanimate);    Gets the animated GIF file to be loaded M_img=image.fromfile (application.startuppath+ "\\loading.gif"); Call Start Animation method Beginanimate ();} Start animation method private void Beginanimate () {if (m_img!=null) {//When an animated GIF is transformed one frame at a time, an event is triggered, which is when the current image is transformed by a frame,        The method associated with the current delegate is called.    Imageanimator.animate (M_img,evthandler); The method that the}}//delegate is associated with private void Onimageanimate (Object sender, EventArgs e) {//In this method, just makes the current winfor redraw, Then go to call the WinForm's OnPaint () method to redraw) this. Invalidate ();} Gets the next frame that needs to be rendered for the current GIF animationprivate void UpdateImage () {imageanimator.updateframes (m_image) when any next action on the current GIF animation is performed on that frame) Turns off the display animation, which can be called when the WinForm is closed or a button's trigger event to stop rendering the current GIF animation.    private void Stopanimate () {m_image = null; Imageanimator.stopanimate (M_image,evthandler);}
Finally you can see the GIF animation, if the animation left or on the top of a text "Loading ...", this is not the same as the effect of web2,0, but the implementation of a lot of complex ...

Animated GIF on WinForm: Go

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.