如何使用仪表样式的进度条? [英] How can I use a meter-style progress bar?

查看:101
本文介绍了如何使用仪表样式的进度条?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Vista/7中,Windows资源管理器外壳程序窗口利用一种特殊的静态进度条来显示硬盘驱动器空间.

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 colored and non-animated. It also turns red colored when it gets close to being full (low disk space).

使用消息传递,我可以告诉Windows窗体ProgressBar控件将其状态更新为已暂停"和错误"(分别为黄色和红色),这可以正常工作,但这些仍特定于进度.

Using messaging, I can tell the Windows Forms ProgressBar control to update its state to Paused and Error (yellow and red colored, respectively), which works fine, but these are still specific to progress.

Windows用户体验指南中,它特别指出进度栏的米"变体:

In the Windows User Experience Guidelines, it specifically points out this "meter" variant of the Progress Bar:

此模式不是进度条,但 它是使用进度来实现的 条控制.仪表有一个独特的 希望将它们与真实情况区分开 进度条.

This pattern isn't a progress bar, but it is implemented using the progress bar control. Meters have a distinct look to differentiate them from true progress bars.

他们说它是使用进度条控件实现的",所以……怎么做?我可以向控件发送什么消息以使其具有这种行为?

They say it "is implemented using the progress bar control", so... how? What message could I send to the control to have it behave this way?

我已经看到您可以发送消息以设置条形颜色,但是文档说启用了视觉样式时,这些调用将被忽略. Windows API文档中有关原始ProgressBar控件的其他内容似乎都没有建议这样做的方法.我只是坚持制作自定义绘制栏吗?我真的很想尽可能地利用该操作系统,以便该应用程序在不同的OS版本中看起来都保持一致.我意识到,Vista之前的版本可能不支持此功能.

I've seen that you can send messages for setting the bar color, but the documentation says these calls are ignored when visual styles are enabled. Nothing else in the Windows API documentation for raw ProgressBar controls seemed to suggest a way to do this. Am I just stuck making a custom drawn bar? I'd really like to utilize the OS whenever possible so that the application will appear consistent throughout different OS versions. I realize that pre-Vista versions probably won't support this, though.

我正在寻找Windows窗体解决方案,但我想知道它是否甚至通过Win32 API完全公开了.

I'm looking for a Windows Forms solution, but I wonder if it is even exposed at all via Win32 API.

推荐答案

可能,但不能通过ProgressBar. Win7也不使用PB绘制这些仪表,也没有与该栏关联的窗口句柄.它必须使用自定义绘图.在WinForms中以及VisualStyleRenderer类中都是可行的.但是,没有帮助的一件事是,即使在.NET 4.0中也没有声明所需的视觉样式部分和状态.

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));
    }
  }
}

我从vsstyle.h SDK头文件中获得了零件号和状态号.

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

这篇关于如何使用仪表样式的进度条?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆