Is is possible to disable Application.EnableVisualStyles();
programmatically? I wanted to turn off the visual styles for a certain part of my application where I could have a colored progress bar. I know you can use System.Drawing
to draw it on, but this is much more simpler if I could turn it off temporarily. Is this possible or am I going to have to draw it?
Asked
Active
Viewed 1,092 times
0

leppie
- 115,091
- 17
- 196
- 297

Alex Diamond
- 586
- 3
- 27
-
I not sure what you are trying to do but this might help – GreatJobBob Apr 15 '16 at 20:52
-
https://msdn.microsoft.com/en-us/library/system.windows.forms.visualstyles.visualstylestate%28v=vs.110%29.aspx – GreatJobBob Apr 15 '16 at 20:52
2 Answers
0
Credits go to GreatJobBob for linking me the MSDN page, the following achieved what I was looking for.
using System.Windows.Forms.VisualStyles;
Application.VisualStyleState = VisualStyleState.NonClientAreaEnabled;
This let me change the color of my progress bar without changing the rest of my controls and form.

Alex Diamond
- 586
- 3
- 27
0
Create your own progress bar class. Disabling Application.EnableVisualStyles
will cause problems in other UIs such as the MessageBox. Here's a basic class to get you started, just change the forecolor to what you want it to be.
using System;
using System.Drawing;
using System.Windows.Forms;
class MyProgressBar : Control
{
public MyProgressBar()
{
this.SetStyle(ControlStyles.ResizeRedraw, true);
this.SetStyle(ControlStyles.Selectable, false);
Maximum = 100;
this.ForeColor = Color.Red; //This is where you choose your color
this.BackColor = Color.White;
}
public decimal Minimum { get; set; }
public decimal Maximum { get; set; }
private decimal mValue;
public decimal Value
{
get { return mValue; }
set { mValue = value; Invalidate(); }
}
protected override void OnPaint(PaintEventArgs e)
{
var rc = new RectangleF(0, 0, (float)(this.Width * (Value - Minimum) / Maximum), this.Height);
using (var br = new SolidBrush(this.ForeColor))
{
e.Graphics.FillRectangle(br, rc);
}
base.OnPaint(e);
}
}

Paul McCann
- 1
- 3