Example E57
Visible to All Users

Reporting for WinForms - Create a Custom Progress Bar Control

This example demonstrates how to create a custom Progress Bar control and use this control to visualize data.

The report that contains the custom Progress Bar control is shown below:

Custom Progress Bar Control in Report Designer

The report preview is shown in the following image:

Custom Progress Bar Control in Preview

Files to Review

Documentation

More Examples

Does this example address your development requirements/objectives?

(you will be redirected to DevExpress.com to submit your response)

Example Code

ProgressBar.cs(vb)
C#
#region #Reference using DevExpress.XtraPrinting; using DevExpress.XtraReports; using DevExpress.XtraReports.UI; using System.ComponentModel; using System.Drawing; using DevExpress.Utils.Serializing; using DevExpress.XtraReports.Expressions; #endregion #Reference #region #Code namespace WindowsFormsApplication1 { [ToolboxItem(true)] [DefaultBindableProperty("Position")] public class ProgressBar : XRControl { // Implement a static constructor as shown below to add the // "Position" property to the property grid's "Expressions" tab. static ProgressBar() { // Specify an array of events in which the property should be available. string[] eventNames = new string[] { "BeforePrint" }; // Specify the property position in the property grid's "Expressions" tab. // 0 - first, 1000 - last. int position = 0; // Specify an array of the property's inner properties. string[] nestedBindableProperties = null; // Specify the property's category in the property grid's "Expressions" tab. // The empty string corresponds to the root category. string scopeName = ""; // Create and set a description for the "Position" property. ExpressionBindingDescription description = new ExpressionBindingDescription( eventNames, position, nestedBindableProperties, scopeName ); ExpressionBindingDescriptor.SetPropertyDescription( typeof(ProgressBar), nameof(Position), description ); } private float position = 0; private float maxValue = 100; public ProgressBar() { this.ForeColor = SystemColors.Highlight; } [DefaultValue(100)] [Description("The maximum value of the bar position.")] [DisplayName("Max Value")] [Category("Parameters")] [XtraSerializableProperty] public float MaxValue { get { return this.maxValue; } set { if (value <= 0) return; this.maxValue = value; } } [DefaultValue(0)] [Description("The current bar position.")] [DisplayName("Position")] [Category("Parameters")] [XtraSerializableProperty] public float Position { get { return this.position; } set { if (value < 0 || value > maxValue) return; this.position = value; } } /* You can use two bricks to construct a progress bar. The "VisualBrick" corresponds to a rectangle bar, the "PanelBrick" serves as a container for this bar. */ protected override VisualBrick CreateBrick(VisualBrick[] childrenBricks) { // Create and return a panel brick. return new PanelBrick(this); } protected override void PutStateToBrick(VisualBrick brick, PrintingSystemBase ps) { base.PutStateToBrick(brick, ps); // Cast the "brick" variable to the "PanelBrick" type (the type of a brick // created in the "CreateBrick" method). PanelBrick panel = (PanelBrick)brick; // Create a new visual brick to represent a bar. VisualBrick progressBar = new VisualBrick(this); // Hide the brick's borders. progressBar.Sides = BorderSide.None; // Set the foreground color for the bar. progressBar.BackColor = panel.Style.ForeColor; // Calculate the width of the progress bar's filled area. float filledAreaWidth = panel.Rect.Width * (Position / MaxValue); // Create a rectangle to be filled by the foreground color. progressBar.Rect = new RectangleF(0, 0, filledAreaWidth, panel.Rect.Height); // Add the visual brick to the panel brick. panel.Bricks.Add(progressBar); } } } #endregion #Code

Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.