Displaying the animation window when the program execution time is time-consuming operation to indicate the task being in progre

xiaoxiao2021-03-06  40

In the software development process, sometimes we will encounter a long time. At this time, if you can display the animation window to indicate that the task is being processed, it is believed that it will bring a better experience.

First, how to play animations in the window?

When developing with Delphi or VB6, we usually use the Animation control, while although in .NET can also be completed by adding COM reference, it is less convenient, and I feel that there is no silent AVI animation to be more than gif. There are few animations. So I decided to use the way of playing GIF animations with PictureBox, as shown below:

There are two ways when setting animations for Picturebox:

1. Specify the picture file directly to the image property of the picturebox when designing. or

2. Dynamically specify the resource data of the program at runtime: //

AskEMBLY THISSEMBLY = askEMBLY.GETEXECUTINGASSEMBLY ();

Street Imagestream = THISSEMBLY.GETMANIFESTRESOURSOURSTREAM ("dblib.res.filecopy.gif");

Bitmap image = new bitmap (imageStream);

Pbxmain.image = image;

Second, how to ensure timely refreshing of animation? Take a closer test, you will find that the animation is often still stopping when performing time-consuming tasks. In order to be able to play the animation normally, this here I have adopted multi-thread technology.

// ... ...

m_busyform.show ();

m_busyform.refresh ();

Threadstart threaddelegate = new threadstart (loadingData);

Thread newthread = new thread (threaddeLegate);

Newthread.start ();

// ... ...

Private void loadingData ()

{

//

/ / Execute your time consumption

//

// ... ...

// Hide or close the animation window

m_busyform.hide ();

}

转载请注明原文地址:https://www.9cbs.com/read-60588.html

New Post(0)