2012-05-22 60 views
0

我需要一個酒吧,指示的東西,如電池engry或硬盤使用的空間大小的百分比。像enter image description here酒吧指示的百分比,但不是一個進度條

這不是一個進度條。當我使用進度條時,每發送一條消息PBM_SETPOS,它都會從0增加到pos。

該欄必須具備手動設置值的能力,在此之後,它會直接將顏色區域更改爲指定的長度,而不是以增加的方式。

WinAPI是否具有用於此目的的構建函數?

+3

可以使用進度條爲此,您只需要解決Vista中添加的*增強功能之一。即增加位置時使用的動畫。閱讀我的答案在這裏瞭解如何:http://stackoverflow.com/questions/6128287/tprogressbar-never-fills-up-all-the-way-seems-to-be-updating-too-fast/6128562#6128562 –

+1

所以'每次你將進度條設置爲N之後立即將其設置爲N-1。'是解決方案嗎?我會嘗試,但聲音we ..... .....謝謝 – user565739

+2

是的。這很奇怪,但它是如何隨着這種控制而變化的。 –

回答

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;