5.4 KiB
title, ms.date, dev_langs, helpviewer_keywords, ms.assetid
| title | ms.date | dev_langs | helpviewer_keywords | ms.assetid | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Create Control That Shows Progress | 03/30/2017 |
|
|
24c5a2e3-058c-4b8d-a217-c06e6a130c2f |
How to: Create a Windows Forms Control That Shows Progress
The following code example shows a custom control called FlashTrackBar that can be used to show the user the level or the progress of an application. It uses a gradient to visually represent progress.
The FlashTrackBar control illustrates the following concepts:
-
Defining custom properties.
-
Defining custom events. (
FlashTrackBardefines theValueChangedevent.) -
Overriding the xref:System.Windows.Forms.Control.OnPaint%2A method to provide logic to draw the control.
-
Computing the area available for drawing the control by using its xref:System.Windows.Forms.Control.ClientRectangle%2A property.
FlashTrackBardoes this in itsOptimizedInvalidatemethod. -
Implementing serialization or persistence for a property when it is changed in the Windows Forms Designer.
FlashTrackBardefines theShouldSerializeStartColorandShouldSerializeEndColormethods for serializing itsStartColorandEndColorproperties.
The following table shows the custom properties defined by FlashTrackBar.
| Property | Description |
|---|---|
AllowUserEdit |
Indicates whether the user can change the value of the flash track bar by clicking and dragging it. |
EndColor |
Specifies the ending color of the track bar. |
DarkenBy |
Specifies how much to darken the background with respect to the foreground gradient. |
Max |
Specifies the maximum value of the track bar. |
Min |
Specifies the minimum value of the track bar. |
StartColor |
Specifies the starting color of the gradient. |
ShowPercentage |
Indicates whether to display a percentage over the gradient. |
ShowValue |
Indicates whether to display the current value over the gradient. |
ShowGradient |
Indicates whether the track bar should display a color gradient showing the current value. |
- Value |
Specifies the current value of the track bar. |
The following table shows additional members defined by FlashTrackBar: the property-changed event and the method that raises the event.
| Member | Description |
|---|---|
ValueChanged |
The event that is raised when the Value property of the track bar changes. |
OnValueChanged |
The method that raises the ValueChanged event. |
Note
FlashTrackBaruses the xref:System.EventArgs class for event data and xref:System.EventHandler for the event delegate.
To handle the corresponding EventName events, FlashTrackBar overrides the following methods that it inherits from xref:System.Windows.Forms.Control?displayProperty=nameWithType:
To handle the corresponding property-changed events, FlashTrackBar overrides the following methods that it inherits from xref:System.Windows.Forms.Control?displayProperty=nameWithType:
Example
The FlashTrackBar control defines two UI type editors, FlashTrackBarValueEditor and FlashTrackBarDarkenByEditor, which are shown in the following code listings. The HostApp class uses the FlashTrackBar control on a Windows Form.
[!code-csharpSystem.Windows.Forms.FlashTrackBar#1] [!code-vbSystem.Windows.Forms.FlashTrackBar#1]
[!code-csharpSystem.Windows.Forms.FlashTrackBar#10] [!code-vbSystem.Windows.Forms.FlashTrackBar#10]
[!code-csharpSystem.Windows.Forms.FlashTrackBar#20] [!code-vbSystem.Windows.Forms.FlashTrackBar#20]
[!code-csharpSystem.Windows.Forms.FlashTrackBar#30] [!code-vbSystem.Windows.Forms.FlashTrackBar#30]