How to create a custom progress bar in WinForm

Source: Internet
Author: User

I found an interesting progress bar control on the internet two days ago and shared it with you. By the way, I recorded my learning experience.

First, take a screenshot to see the effect:

As a result of project requirements, it is inevitable that the progress bar will be involved to show the execution progress to users in complicated execution. On the codeproject, I saw a Progress bar control called Progress-O-Doom. I thought it was quite interesting and I came back to study it. It is found that the progress bar is painted by some sub-controls, including the border, the scroll bar background, and the scroll bar. It seems that a progress bar is broken down into several items to draw separately, and some of them can be freely combined. The progress bar finally combined can have multiple effects. You can test it on your own, it's time to test your imagination.

In addition to the basic ProgressBarEx control, there are several built-in scroll bar controls, including Rar-style RarProgressBar and DualProgressBar with layer-2 scroll bars. according to the design of the author, only one ProgressBarEx is required, and some ProgressPainter, BackgroundPainter, and BorderPainter can be combined to form a cool progress bar. ProgressPainter can also set its own GlossPainter and BorderPainter attributes, while BackgroundPainter can also set its GlossPainter attributes. This flexible combination is very convenient, in addition, the author has a visual interface, dragging and dropping, and clicking the mouse to set it, you can get a cool progress bar.

Using a DualProgressBar can solve the needs of my project, because I have a two-layer for loop, the first-layer scroll bar shows the outer loop, and the second-layer scroll bar shows the lower-layer loop, which is quite good.

First, place a DualProgressBar on the form. This type of scroll bar requires four painters to describe. Therefore, you can select the Painter of the corresponding type on the form, then set Painter attributes, mainly color and style. Some also involve two colors. Some styles can be highlighted, concave, or flattened with the form, 3D effects. In fact, if you set MasterValue and Value like this progress bar, you can see that it is actually a combination of two progress bars during design. Here, MasterPainter and ProgressPainter must be set to two different ProgressPainter. At least they must have different colors before they can be seen that the two are scrolling at the same time.

The background code is also relatively simple to use, mainly to assign values to MasterValue and Value. Set two parameters. The first parameter is the number of cycles at the first layer, and the second parameter is the number of cycles at the second layer.

/// <summary>
/// Shows the progress.
/// </summary>
/// <param name="firstLoop">The first loop count.</param>
/// <param name="secondLoop">The second loop count.</param>
private void ShowProgress(int firstLoop, int secondLoop)
{
    dualProgressBar1.Value = 0;
    dualProgressBar1.MasterValue = 0;
    dualProgressBar1.Maximum = secondLoop;
Related Article

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.