This example creates a custom progress bar editor that can display its progress along with a progress bar:
Files to Review
Documentation
Does this example address your development requirements/objectives?
(you will be redirected to DevExpress.com to submit your response)
Example Code
C#using DevExpress.XtraEditors;
using DevExpress.XtraEditors.Drawing;
using DevExpress.XtraEditors.Registrator;
using DevExpress.XtraEditors.Repository;
using DevExpress.XtraEditors.ViewInfo;
using DevExpress.XtraPrinting;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
namespace WindowsApplication1
{
public class MyProgressBarControl : ProgressBarControl
{
static MyProgressBarControl()
{
RepositoryItemMyProgressBarControl.RegisterMyProgressBarControl();
}
public MyProgressBarControl()
: base()
{
}
public override string EditorTypeName {
get {
return RepositoryItemMyProgressBarControl.MyProgressBarControlName;
}
}
public new RepositoryItemMyProgressBarControl Properties {
get {
return (RepositoryItemMyProgressBarControl)base.Properties;
}
}
[UserRepositoryItem("RegisterMyProgressBarControl")]
public class RepositoryItemMyProgressBarControl : RepositoryItemProgressBar
{
public const string MyProgressBarControlName = "MyProgressBarControl";
static RepositoryItemMyProgressBarControl()
{
RegisterMyProgressBarControl();
}
public RepositoryItemMyProgressBarControl()
: base()
{
}
public override VisualBrick GetBrick(PrintCellHelperInfo info)
{
Bitmap bmp = new Bitmap(info.Rectangle.Width, info.Rectangle.Height);
Graphics gr = Graphics.FromImage(bmp);
gr.FillRectangle(new SolidBrush(Color.White), info.Rectangle);
ImageBrick brick = new ImageBrick(BorderSide.None, 0, Color.Transparent, Color.Transparent);
int width = Convert.ToInt32(info.Rectangle.Width * Convert.ToDouble(info.EditValue) / ((double)100));
if(width > 0)
{
gr.FillRectangle(new LinearGradientBrush(new Rectangle(0, 0, width, info.Rectangle.Height), Color.LightBlue, Color.White, 90, true), new Rectangle(0, 0, width, info.Rectangle.Height));
brick.Image = bmp;
}
gr.DrawString(info.DisplayText, info.Appearace.Font, new SolidBrush(Color.Black), new PointF(0, 0));
brick.Rect = info.Rectangle;
return brick;
}
public static void RegisterMyProgressBarControl()
{
EditorRegistrationInfo.Default.Editors.Add(new EditorClassInfo(MyProgressBarControlName, typeof(MyProgressBarControl), typeof(RepositoryItemMyProgressBarControl), typeof(MyProgressBarViewInfo), new ProgressBarPainter(), true));
}
public override string EditorTypeName {
get {
return MyProgressBarControlName;
}
}
}
public class MyProgressBarViewInfo : ProgressBarViewInfo
{
public MyProgressBarViewInfo(RepositoryItem item)
: base(item)
{
}
}
}
}
C#using System;
using System.Data;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
Random random = new Random();
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
gridControl1.ShowPrintPreview();
}
private void Form1_Load(object sender, EventArgs e)
{
productsBindingSource.DataSource = GetProductsDataTable();
}
DataTable GetProductsDataTable()
{
DataTable table = new DataTable();
table.TableName = "Products";
table.Columns.Add(new DataColumn("ProductName", typeof(string)));
table.Columns.Add(new DataColumn("UnitPrice", typeof(double)));
table.Columns.Add(new DataColumn("UnitsOnOrder", typeof(int)));
for(int i = 0; i < 20; i++)
{
int index = i + 1;
table.Rows.Add("Product " + index, Math.Round(random.NextDouble() * 1000, 2), random.Next(0, 9) * 10);
}
return table;
}
}
}