Custom General WinForm progress bar ITSProgramBar

Source: Internet
Author: User

I. Running effect:

If there is a picture and there is truth, we should be quick first.

 

Ii. Development requirements:

1. The progress bar user control used in WinForm.

2. Call location. You do not need to write multi-thread processing code to control UI display and Background Service Execution.

3. Common codes. developers can use "input parameters" and "Call functions" in other forms to display progress bars ".

4. The progress bar uses background processing functions and interface refresh functions as "input parameters ".

5. The progress bar receives the "Progress Display message" and "termination progress message" sent to the user's background business code ".

6. The progress bar is asynchronously refreshed to the UI of the main form interface and the UI of the progress bar, and the display process is accurate and consistent.

 

Iii. Interface Definition

1. Main Fields

View Code

/// <Summary> /// function interface for backend Service Processing /// </summary> public Func <object, object> DoWork_Func = null; /// <summary> /// function interface parameters for backend Service Processing /// </summary> public object DoWork_FuncParam = null; /// <summary> // function interface refreshed on the front-end interface // </summary> // public Action UIShow_Func = null; public Action <object> UIShow_Func = null;

 

2. Progress Control

View Code

/// <Summary> /// progress bar /// </summary> public void StartRun () /// <summary> /// pause the progress bar /// </summary> public void PauseRun () /// <summary> /// termination progress bar /// </summary> public void StopRun () /// <summary> /// receives the "execution progress message" sent externally /// </summary> /// <param name = "percent"> </param> /// <param name = "msg"> </param> public void SendRunMsg (int percent, string msg) /// <summary> /// receive the "termination progress message" sent externally /// </summary> /// <param name = "msg"> </param> public void SendStopMsg (string msg) /// <summary> /// whether the progress bar is terminated /// </summary> /// <returns> </returns> public bool IsStop ()

 

3. Modify the style

View Code

/// <Summary> /// set the title of the progress bar /// </summary> /// <param name = "title"> </param> public void SetTitle (string title) /// <summary> /// set the foreground color to display the progress bar status /// </summary> /// <returns> </returns> public void SetForeColor (int alpha, int red, int green, int blue) /// <summary> /// set the background color for the progress bar Status display /// </summary> /// <returns> </returns> public void SetBackColor (int red, int green, int blue)

 

4. frontend call

View Code

Private void Start_Click (object sender, EventArgs e) {MyBar. setTitle ("the task execution progress is shown as follows"); // set the progress bar title MyBar. setForeColor (0,173,208, 3); // set the front-end color of the progress bar, MyBar. setBackColor (255,255,255); // set the progress bar background color MyBar. doWork_Func = this. doWork; // specifies the background service processing function MyBar of the progress bar. doWork_FuncParam = 10000*1; // specifies the entry parameter MyBar of the background service processing function of the progress bar. UIShow_Func = this. UIShow; // specify the front-end UI of the progress bar to display the function MyBar. startRun (); // progress bar} private void Stop_C Lick (object sender, EventArgs e) {if (MyBar! = Null) {MyBar. StopRun (); // termination progress bar }}

 

 

Iv. Instructions for use

When using this progress bar, you only need to introduce the dll file to other WinForm projects.

The rest of the work is to initialize parameters and call interface methods in the background of the main interface.

 

 

 

 

 

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.