Overriding the OnPaint event to redraw a form (display animated GIF) Instance 2

Source: Internet
Author: User

    /// <summary>    ///forms that can display GIF/// </summary>     Public classWingif:form {PrivateImage _img =NULL;  PublicImage Img {Get{return_img;} Set{_img =value;} }        PrivateEventHandler Evthandler =NULL;  Publicwingif (Image img) {//Initialize SettingsEvthandler =NewEventHandler (onimageanimate);  This. IMG =img;  This. Width = _img. width+ -;  This. Height = _img. Height + -; //Start Animationbeginanimate (); }        //the method that the delegate is associated with        Private voidonimageanimate (Object sender, EventArgs e) {//This method only causes the current control to redraw, calling OnPaint ()             This.        Invalidate (); }        //Set start animation         Public voidbeginanimate () {if(_img! =NULL)            {                //An event is triggered when an animated GIF is converted to a frame every time after a certain period .//This method invokes the method associated with the current delegate when the current image is transformed one frame at a time .imageanimator.animate (_img,evthandler); }        }        //turns off the display animation, which stops rendering the current GIF animation when the window is closed or when an event is triggered         Public voidstopanimate () {_img=NULL;        Imageanimator.stopanimate (_img,evthandler); }        /// <summary>        ///overloaded Current WinForm OnPaint method that displays a frame of a GIF when the interface is drawn/// </summary>        protected Override voidOnPaint (PaintEventArgs e) {Base.            OnPaint (e); if(_img! =NULL)            {                //gets the next frame to render for the current GIF animationUpdateImage (); //The frame you want to render for the current GIF animation is displayed somewhere in the interfaceE.graphics.drawimage (_img,NewRectangle (0,0, _img. Width,_img.            Height)); }        }        //gets the next frame of the current GIF animation that needs to be rendered, and any next action on the current GIF animation is to manipulate the frame        Private voidUpdateImage () {imageanimator.updateframes (_img); }    }

Use and Results display:

        Private void button1_click (object  sender, EventArgs e)        {                       string'\ \2.gif";             = System.Drawing.Image.FromFile (file);             New wingif (IMG);            Gif. Show ();        }

Overriding the OnPaint event to redraw a form (display animated GIF) Instance 2

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.