Windform loading animation, showing gif dynamic pictures (lazy recommended)

To do a little thing, you need to make a loading interface and loading animation.

The first is to use picturebox to add animation, run it, and find that the gif is not moving.

Later, there were no more than two kinds of searches on the Internet, GDI redrawing. Use other plugins.

Then the problem comes, for a lazy person like me, I don't want to write so much code. So is there a way to display the gif image directly? Yes.

That is to use the WebBrowser control, did not think of it, haha, enough YD!

first   design drawing

renderings


gif image storage location


code map


Form code (the actual code is less than 10 lines)

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;

namespace file monitoring service
{
    public partial class LoadForm : Form
    {
        /// <summary>
        /// Initialize
        /// </summary>
        /// <param name="text">Load prompt information</param>
        public LoadForm(string text= "Loading, please wait...")
        {
            InitializeComponent();
            Control.CheckForIllegalCrossThreadCalls = false;
            this.label1.Text = text;
            var path=Application.StartupPath;
            path = path.Substring(0, path.LastIndexOf("\\"));
            path = path.Substring(0, path.LastIndexOf("\\"));
            this.webBrowser1.Url = new Uri(path + "\\loading.gif");
        }

        /// <summary>
        /// closure
        /// </summary>
        private void CloseButtom_Click(object sender, EventArgs e)
        {
            this.Close();
        }



    }
}
If you are interested, you can try it. Lazy people are the driving force behind development.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325627633&siteId=291194637