How can I use a meter-style progress bar?

后端 未结 1 495
感动是毒
感动是毒 2020-12-03 05:59

In Vista/7, the Windows Explorer shell window makes use of a special kind of static progress bar to display hard drive space.

With default styles, this bar is blue c

相关标签:
1条回答
  • 2020-12-03 06:44

    It is possible, but not through ProgressBar. Nor does Win7 use a PB to draw those meters, there is no window handle associated with the bar. It must be using custom drawing. That's possible in WinForms as well with the VisualStyleRenderer class. One thing that doesn't help however is that the required visual style parts and states are not declared, not even in .NET 4.0.

    This sample form reproduces the meter bar:

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    using System.Windows.Forms.VisualStyles;
    
    namespace WindowsFormsApplication1 {
      public partial class Form1 : Form {
        public Form1() {
          InitializeComponent();
        }
        VisualStyleRenderer renderer = new VisualStyleRenderer(VisualStyleElement.ProgressBar.Bar.Normal);
        protected override void OnPaint(PaintEventArgs e) {
          renderer.SetParameters("PROGRESS", 11, 2);
          renderer.DrawBackground(e.Graphics, new Rectangle(10, 10, 200, 15));
          renderer.SetParameters("PROGRESS", 5, 4);
          renderer.DrawBackground(e.Graphics, new Rectangle(10, 10, 100, 15));
        }
      }
    }
    

    I got the part and state numbers from the vsstyle.h SDK header file.

    0 讨论(0)
提交回复
热议问题