Progress Bar Back Color - Change?

Is there a way to change the progress bar back color? Not certain if iti matters but am on a mobile form?
tbaseflugAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vinhnlCommented:
Hi Tbaseflug, see this sample: http://www.codeproject.com/cs/miscctrl/StatusColorProgressBar.asp

Good luck,
VINHNL
tbaseflugAuthor Commented:
Not certain if these will work in a mobile app
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Bob LearnedCommented:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;

[DefaultProperty("Value")]
public class ProgressBarEx : System.Windows.Forms.Control
{
  private const Int32 WM_USER = 1024;
  private const Int32 PBM_SETRANGE = (WM_USER + 1);
  private const Int32 PBM_SETPOS = (WM_USER + 2);
  private const Int32 PBM_DELTAPOS = (WM_USER + 3);
  private const Int32 PBM_SETSTEP = (WM_USER + 4);
  private const Int32 PBM_STEPIT = (WM_USER + 5);
  private const Int32 PBM_SETRANGE32 = (WM_USER + 6);
  private const Int32 PBM_GETRANGE = (WM_USER + 7);
  private const Int32 PBM_GETPOS = (WM_USER + 8);
  private const Int32 CCM_FIRST = 8192;
  private const Int32 PBM_SETBKCOLOR = (CCM_FIRST + 1);
  private const Int32 PBM_SETBARCOLOR = (WM_USER + 9);

  [DllImport("comctl32.dll")]
  private static extern bool InitCommonControlsEx(INITCOMMONCONTROLS icc);

  [DllImport("user32.dll", CharSet=CharSet.Auto)]
  public static extern IntPtr SendMessage(HandleRef hWnd, int msg, int wParam, int lParam);

  public ProgressBarEx()
  {
    this.Minimum = 0;
    this.Maximum = 100;
    this.Step = 10;
    this.Value = 0;
    base.SetStyle((ControlStyles.Selectable | ControlStyles.UserPaint), false);
  }

  protected override void CreateHandle()
  {
    if (!(base.RecreatingHandle))
    {
      INITCOMMONCONTROLS initcommoncontrolsex1 = new INITCOMMONCONTROLS();
      initcommoncontrolsex1.dwICC = 32;
      InitCommonControlsEx(initcommoncontrolsex1);
    }
    base.CreateHandle();
  }

  public void Increment(int value)
  {
    this.Value = (this.Value + value);
    if ((this.Value < this.Minimum))
    {
      this.Value = this.Minimum;
    }
    if ((this.Value > this.Maximum))
    {
      this.Value = this.Maximum;
    }
    this.UpdatePos();
  }
  private Color m_barColor = SystemColors.ActiveCaption;

  [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  public Color BarColor
  {
    get
    {
      return m_barColor;
    }
    set
    {
      m_barColor = value;
      SendMessage(new HandleRef(this, this.Handle), PBM_SETBARCOLOR, 0, ColorTranslator.ToWin32(this.BarColor));
    }
  }

  protected override void OnHandleCreated(EventArgs e)
  {
    base.OnHandleCreated(e);
    SendMessage(new HandleRef(this, this.Handle), PBM_SETRANGE32, this.Minimum, this.Maximum);
    SendMessage(new HandleRef(this, this.Handle), PBM_SETSTEP, this.Step, 0);
    SendMessage(new HandleRef(this, this.Handle), PBM_SETPOS, this.Value, 0);
    SendMessage(new HandleRef(this, this.Handle), PBM_SETBARCOLOR, 0, ColorTranslator.ToWin32(this.BarColor));
    SendMessage(new HandleRef(this, this.Handle), PBM_SETBKCOLOR, 0, ColorTranslator.ToWin32(this.BackColor));
  }

  public void PerformStep()
  {
    this.Increment(this.Step);
  }

  public override string ToString()
  {
    string text1 = base.ToString();
    return string.Concat(new string[]{text1, ", Minimum: ", this.Minimum.ToString(), ", Maximum: ", this.Maximum.ToString(), ", Value: ", this.Value.ToString()});
  }

  private void UpdatePos()
  {
    if (base.IsHandleCreated)
    {
      SendMessage(new HandleRef(this, this.Handle), PBM_SETPOS, this.Value, 0);
    }
  }

  [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  public override bool AllowDrop
  {
    get
    {
      return base.AllowDrop;
    }
    set
    {
      base.AllowDrop = value;
    }
  }
  private Color m_backColor = SystemColors.Control;

  [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  public override Color BackColor
  {
    get
    {
      return m_backColor;
    }
    set
    {
      m_backColor = value;
      SendMessage(new HandleRef(this, this.Handle), PBM_SETBKCOLOR, 0, ColorTranslator.ToWin32(this.BackColor));
    }
  }

  [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  public override Image BackgroundImage
  {
    get
    {
      return base.BackgroundImage;
    }
    set
    {
      base.BackgroundImage = value;
    }
  }

  [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  public new bool CausesValidation
  {
    get
    {
      return base.CausesValidation;
    }
    set
    {
      base.CausesValidation = value;
    }
  }

  protected override CreateParams CreateParams
  {
    get
    {
      CreateParams params1 = base.CreateParams;
      params1.ClassName = "msctls_progress32";
      return params1;
    }
  }

  protected override ImeMode DefaultImeMode
  {
    get
    {
      return ImeMode.Disable;
    }
  }

  protected override Size DefaultSize
  {
    get
    {
      return new Size(100, 23);
    }
  }

  [EditorBrowsable(EditorBrowsableState.Never), Browsable(false)]
  public override Font Font
  {
    get
    {
      return base.Font;
    }
    set
    {
      base.Font = value;
    }
  }

  [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  public override Color ForeColor
  {
    get
    {
      return base.ForeColor;
    }
    set
    {
      base.ForeColor = value;
    }
  }

  [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  public new ImeMode ImeMode
  {
    get
    {
      return base.ImeMode;
    }
    set
    {
      base.ImeMode = value;
    }
  }

  [Description("ProgressBarMaximumDescr"), RefreshProperties(RefreshProperties.Repaint), DefaultValue(100), Category("CatBehavior")]
  public int Maximum
  {
    get
    {
      return _maximum;
    }
    set
    {
      if ((this.Maximum != value))
      {
        if ((value < 0))
        {
          throw new ArgumentException("Invalid maximum argument");
        }
        if ((this.Minimum > value))
        {
          _minimum = value;
        }
        _maximum = value;
        if ((this.Value > this.Maximum))
        {
          this.Value = this.Maximum;
        }
        if (base.IsHandleCreated)
        {
          SendMessage(new HandleRef(this, this.Handle), PBM_SETRANGE32, this.Minimum, this.Maximum);
          this.UpdatePos();
        }
      }
    }
  }

  [RefreshProperties(RefreshProperties.Repaint), Description("ProgressBarMinimumDescr"), Category("CatBehavior"), DefaultValue(0)]
  public int Minimum
  {
    get
    {
      return _minimum;
    }
    set
    {
      if ((this.Minimum != value))
      {
        if ((value < 0))
        {
          throw new ArgumentException("Invalid lower bound argument: Minimum");
        }
        if ((this.Maximum < value))
        {
          _maximum = value;
        }
        _minimum = value;
        if ((this.Value < this.Minimum))
        {
          this.Value = this.Minimum;
        }
        if (base.IsHandleCreated)
        {
          SendMessage(new HandleRef(this, this.Handle), PBM_SETRANGE32, this.Minimum, this.Maximum);
          this.UpdatePos();
        }
      }
    }
  }

  [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  public override RightToLeft RightToLeft
  {
    get
    {
      return base.RightToLeft;
    }
    set
    {
      base.RightToLeft = value;
    }
  }

  [Description("ProgressBarStepDescr"), DefaultValue(10), Category("CatBehavior")]
  public int Step
  {
    get
    {
      return _step;
    }
    set
    {
      _step = value;
      if (base.IsHandleCreated)
      {
        SendMessage(new HandleRef(this, this.Handle), PBM_SETSTEP, this.Step, 0);
      }
    }
  }

  [Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  public new bool TabStop
  {
    get
    {
      return base.TabStop;
    }
    set
    {
      base.TabStop = value;
    }
  }

  [Bindable(false), Browsable(false), EditorBrowsable(EditorBrowsableState.Never)]
  public override string Text
  {
    get
    {
      return base.Text;
    }
    set
    {
      base.Text = value;
    }
  }

  [DefaultValue(0), Description("ProgressBarValueDescr"), Bindable(true), Category("CatBehavior")]
  public int Value
  {
    get
    {
      return _value;
    }
    set
    {
      if ((this.Value != value))
      {
        if (((value < this.Minimum) || (value > this.Maximum)))
        {
          throw new ArgumentException("Invalid bound argument");
        }
        _value = value;
        this.UpdatePos();
      }
    }
  }
  private int _maximum;
  private int _minimum;
  private int _step;
  private int _value;
  [StructLayout(LayoutKind.Sequential, Pack=1)]
    private class INITCOMMONCONTROLS
  {

    public INITCOMMONCONTROLS()
    {
      this.dwSize = 8;
    }
    public int dwICC;
    public int dwSize;
  }
}

Sample:
   this.progressBar1.BarColor = Color.Red;
   this.progressBar1.BackColor = Color.White;

Bob

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tbaseflugAuthor Commented:
Bob -

Will this work in a mobile app
Bob LearnedCommented:
I overlooked "mobile" :(  

I have no idea, but I don't think so.

Bob
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.