0

When overriding OnPaint() and OnPaintBackground() events as follows :

protected override void OnPaint( PaintEventArgs e ) {
    base.OnPaint( e );
    try {
        switch ( TextVisibility  ) {
            case ProgressBarTextVisibility.None:
                return;
            case ProgressBarTextVisibility.CustomText:
                if ( progressText=="" ) { return; }
                break;
            case ProgressBarTextVisibility.Percentage:
                progressText = Value.ToString()+"%";
                break;
        }

        SizeF charSize = e.Graphics.MeasureString( progressText, ProgressFont );
        e.Graphics.DrawString(
            progressText,
            ProgressFont,
            new SolidBrush(ProgressTextColor),
            new PointF(
                Width/2-( charSize.Width/2.0F ),
                Height/2-( charSize.Height/2.0F )
            )
        );

    } catch ( Exception ee ) {

    }
}

protected override void OnPaintBackground( PaintEventArgs pevent ) {
    base.OnPaintBackground( pevent );
}

The result is this (progressbar is at 50%) [ pointing out that the background is not drawn at all. ] :

enter image description here

I get the same result as depicted above if i create a new Label control and set it's background to Color.Transparent and set dock to Full.

There are plenty of examples on how to add text AND draw a custom progress bar style, however I wish to keep the original progress bar visual in-tact without re-inventing the wheel. The progress portion works fine and I am happy with the native style and do not wish to redraw my own custom adaptation of it. I only wish to overlay text on top.

I have considered a Timer control / etc, however I also wish to keep this using as few resources as possible.

Here are some of the resources I have already been through :

I am using c# and the control is a custom control that extends the .NET native ProgressBar control.

UPDATE

I will use this section to post ongoing research as I find more relevant data that is different.

Community
  • 1
  • 1
Kraang Prime
  • 9,981
  • 10
  • 58
  • 124

1 Answers1

-1

Override OnLoad and call SetStyle(ControlStyles.AllPaintingInWmPaint, false) and SetStyle(ControlStyles.UserPaint, true). That will separate background and control detail drawing.