2010-08-18 69 views
1

我發現了一個巨大的C#示例,基於如何大或小的值的顏色細胞橙色深淺不同的是: http://demos.devexpress.com/ASPxTreeListDemos/Appearance/ConditionalFormatting.aspx(C#)條件格式

的問題是它希望這些數字對於它的運作非常大。有沒有使用數學公式的方法,我可以指定最大和最小的數字(或所有數字,如果需要),並讓它以這種方式計算橙色陰影。

這裏是從上面的鏈接的具體代碼:

protected void treeList_HtmlDataCellPrepared(object sender, TreeListHtmlDataCellEventArgs e) { 
    if(e.Column.Name == "budget") { 
     decimal value = (decimal)e.CellValue; 
     e.Cell.BackColor = GetBudgetColor(value); 
     if(value > 1000000M) 
      e.Cell.Font.Bold = true 
    } 
} 

Color GetBudgetColor(decimal value) { 
    decimal coeff = value/1000 - 22; 
    int a = (int)(0.02165M * coeff); 
    int b = (int)(0.09066M * coeff); 
    return Color.FromArgb(255, 235 - a, 177 - b); 
} 

我假設的數量乘以該係數_能以某種方式計算。有任何想法嗎?

回答

0

嘗試改變這一行decimal coeff = value/1000 - 22;decimal coeff = value/100 - 22;

+0

我不明白怎麼會處理的任何數值範圍。我確實在MSDN博客上找到了答案,儘管它使用了不同的方法。謝謝你的迴應! – lpage 2010-08-19 02:10:19