DoEasy. Controls (Part 27): Working on ProgressBar WinForms object

Concept

In the current article, I will continue the development of the ProgressBar control that I started to implement in the previous article. This element consists of two components - the underlay and the progress bar. In the future, it will be possible to place other design elements on the underlay in additino to the progress bar - texts, images, etc. At the moment, this control is a static WinForms object. Today I will develop the functionality for programmatically controlling the progress bar of the object. Thus, we will make it possible to use it in our programs to indicate the progress of any operations that require a significant number of identical actions. Autopip Gold

If we pay attention to similar progress bars in the Windows environment, we will notice the glare moving along the progress bar or some other visual effects when it is filled. Besides the fact that they animate the program interface making it more attractive, the visual effects on the progress bar also carry the function of an additional indication of the process completion. If the number of operations displayed by the progress bar is large enough, then the progress bar is filled not on each completed operation, but after a certain number of them. Thus, even if the progress bar is full, operations can still continue. In such a situation, if visual effects continue to be displayed on the progress bar, then a process has not yet been completed. Once the process is complete, the progress bar will no longer display visual effects.

Usually, when the process ends, the ProgressBar control is also hidden, so the indication described above is not visible. But if the progress bar is created in a separate window, which, upon completion of all operations, should be closed manually, then the indication of the process completion/non-completion can be observed using visual effects on the progress bar. Alternatively, if there are several progress bars at the same time, which display one process divided into subprocesses, the progress bars of already completed processes will be displayed until the overall process is completed. On the ProgressBar controls that display subprocesses, we can also observe the double indication - if the progress bar is completely filled, but visual effects continue to be displayed on it, then this subprocess has not yet completely completed.

Implementing the visual effects functionality for the ProgressBar control will give us the ability to use its concept in other controls in the library. Each object that should have visual effects will be placed in the list of active elements. The library will see this list and call the timer event handlers of each of the objects placed in this list in turn in the timer. The necessary functionality will be implemented in the objects themselves, namely in their timer handler.

In addition, I will slightly refine the drawing of predefined icons. In the last article, I mentioned the strange behavior of anti-aliased lines when drawing them with transparency. Indeed, all graphical primitives drawn using smoothing methods of the Standard Library are not drawn normally if set to transparent. This means, we cannot achieve a smooth appearance or disappearance of such lines. But we can use the following trick: if the color opacity is set to a certain value for the line, for example, from 128 to 255, then we need to draw using the anti-aliasing method. If the opacity is set from 127 to 0, then we draw such a line using the usual method without smoothing. This approach will give the visual effect of a smooth appearance/disappearance of the drawn graphical primitives, and the semi-transparency will hide the "roughness" of the lines drawn without anti-aliasing.

Improving library classes

While creating a glare object in the previous article, I assumed that it would be created on the basis of a shadow object - it would be derived from the shadow object in order to use the blur methods available in that class. However, as practice has shown, this approach has not justified itself - in addition to the fact that it complicates the addition of visual effects to any object, the use of a glare as the successor of a shadow object limits its use within the framework of an already created concept.

So let's do the following: the glare object will be derived from the base object class of all WinForms objects of the CWinFormBase library and will be in the list of auxiliary objects. Then I can easily add it with just one line of code in the class where it should be used. I have already implemented handlers for active objects. This approach will save us from the routine addition of functionality, identical to the functionality of the shadow object processing, to different library classes. We will simply use the ready-made methods for adding bound objects and processing them.

Visit Link - https://www.mql5.com/en/users/neillson01/seller