基于C#桌面应用程序的加载器动画 [英] Loader animation for C# desktop based application

查看:218
本文介绍了基于C#桌面应用程序的加载器动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在jquery ajax中,是否有类似的方法可以在C#中完成?

Is there a way that similar in jquery ajax beforeSend and complete in C#?

因为在网络上我通常会在按下添加按钮之类的按钮时进行操作,所以我将beforendSend:设置为显示图像并在complete:中隐藏图像的功能

Because in web I usually do when pressing like an add button i set beforendSend: a function to show an image and hide image function in complete:

现在我想在C#桌面应用程序中进行操作.有没有类似的东西?就像使用进度条一样

And now I want to do in C# desktop application. Is there any similar to that? like some kind of using a progress bar

推荐答案

您将需要执行后台处理和UI回调.下面是一个非常简单的示例:

You will need to perform background processing and UI callbacks. Very simple example below:

private void button3_Click(object sender, EventArgs e)
    {
        ProcessingEvent += AnEventOccurred;

        ThreadStart threadStart = new ThreadStart(LongRunningProcess);
        Thread thread = new Thread(threadStart);
        thread.Start();
    }

    private void LongRunningProcess()
    {
        RaiseEvent("Start");

        for (int i = 0; i < 10; i++)
        {
            RaiseEvent("Processing " + i);
            Thread.Sleep(1000);
        }

        if (ProcessingEvent != null)
        {
            ProcessingEvent("Complete");
        }
    }

    private void RaiseEvent(string whatOccurred)
    {
        if (ProcessingEvent != null)
        {
            ProcessingEvent(whatOccurred);
        }
    }

    private void AnEventOccurred(string whatOccurred)
    {
        if (this.InvokeRequired)
        {
            this.Invoke(new Processing(AnEventOccurred), new object[] { whatOccurred });
        }
        else
        {
            this.label1.Text = whatOccurred;
        }
    }

    delegate void Processing(string whatOccurred);

    event Processing ProcessingEvent;

这篇关于基于C#桌面应用程序的加载器动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆