Pieter
Pieter

Reputation: 32795

Windows 98-style progress bar

I use Windows 7, so my progress bars all have that green look. I'd like something a little more simplistic though, perhaps something resembling the Windows 98 progress bar.

Is there a simple way to change the style of the progress bar or will I have to recreate it manually?

Upvotes: 8

Views: 2386

Answers (3)

Adam Pierce
Adam Pierce

Reputation: 34365

I like Hans' answer but there's no need to override the control's class. You can remove the Win7 style from an individual control simply by calling SetWindowTheme using the control's handle. Here's an example:

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace MyApplication
{
    public partial class Form1 : Form
    {
        [DllImport("uxtheme", ExactSpelling = true, CharSet = CharSet.Unicode)]
        public extern static Int32 SetWindowTheme(IntPtr hWnd,
                      String textSubAppName, String textSubIdList);

        public Form1()
        {
            InitializeComponent();

            // Remove Win7 formatting from the progress bar.
            SetWindowTheme(progressBar1.Handle, "", "");

Upvotes: 1

Hans Passant
Hans Passant

Reputation: 942000

You cannot easily get the exact Win98 look without a pretty drastic rewrite of the control. But a simple flat light-blue progress bar can be had by turning off visual styles. Like this:

using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

class SimpleProgressBar : ProgressBar {
    protected override void OnHandleCreated(EventArgs e) {
        base.OnHandleCreated(e);
        if (Environment.OSVersion.Version.Major >= 6) {
            SetWindowTheme(this.Handle, "", "");
        }
    }
    [DllImport("uxtheme.dll")]
    private static extern int SetWindowTheme(IntPtr hWnd, string appname, string idlist);
}

Upvotes: 9

Brad
Brad

Reputation: 163438

I haven't tested this... on an XP machine right now... but I suspect if you turn off "Windows XP Styles" under the framework settings for your application, you will get what you are looking for.

Upvotes: 0

Related Questions