一个指示百分比的栏,但不是进度条

时间:2012-05-22 16:55:39

标签: winapi size percentage indicator

我需要一个指示某个百分比的条形图,例如电池电量或硬盘的空间大小。像enter image description here

这不是进度条。当我使用进度条时,每次发送消息PBM_SETPOS时,它都会从0增加到pos。

条形图必须能够手动设置一个值,然后它会直接将颜色区域更改为指定的长度,而不是以增加的方式。

WinAPI是否具有用于此目的的内置功能?

1 个答案:

答案 0 :(得分:0)

使用面板,然后在其中设置标签...然后根据百分比设置带背景颜色的标签宽度......

代码如下:

string s27 = "select percentage from CandidateReg3 where candidateid='" + candidateid + "'";
DataTable d17 = cn.viewdatatable(s27);
if (d17.Rows.Count > 0) {
   for (int m = 0; m < d17.Rows.Count; m++) {
        percreg3 = int.Parse(d17.Rows[m]["percentage"].ToString());
        percregtotal = percreg3 + percreg;
   }
} else {
   percregtotal = percreg;
}

decimal percregtotals = (decimal)percregtotal / 100;
double percent = Convert.ToDouble(percregtotals);

// double percent = 1;
IndicatorLabel.Width = new Unit(percent * IndicatorPanel.Width.Value, UnitType.Pixel);

IndicatorLabel.ToolTip = percent.ToString("p0");
IndicatorLabel.Text = percent.ToString("p0"); 
IndicatorLabel.ForeColor=Color.White;

// IndicatorLabel.Text = "";
IndicatorLabel.BackColor = Color.Green;