在DevExpress GridView中是否可以將貨幣符號與左邊的值和右邊的值對齊? 貨幣符號左對齊並且GridView中的值正好對齊
1
A
回答
0
此任務超出了常規文本格式。要完成它,您需要手動繪製單元格內容。
XtraGrid爲此提供了事件:CustomDrawCell。 event argument object提供了對圖形對象,單元格邊界以及手動繪製單元文本所需的其他信息的引用。
private void OnGridViewCustomDrawCell(object sender, RowCellCustomDrawEventArgs e) {
switch (e.Column.FieldName) {
case "Debit":
DrawDebitCell(e);
break;
}
}
private void DrawDebitCell(RowCellCustomDrawEventArgs e) {
e.Handled = true;
string text = string.Format(CultureInfo.CurrentCulture, "{0} {1:n2}", CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol, e.CellValue);
Size textSize = e.Appearance.CalcTextSizeInt(e.Cache, text, int.MaxValue);
e.Appearance.DrawBackground(e.Cache, e.Bounds);
if (Convert.ToInt32(textSize.Width) > e.Bounds.Width)
e.Appearance.DrawString(e.Cache, text, e.Bounds);
else {
StringFormat stringFormat = e.Appearance.GetStringFormat();
string valueText = string.Format(CultureInfo.CurrentCulture, "{0:n2}", e.CellValue);
stringFormat.Alignment = StringAlignment.Near;
e.Appearance.DrawString(e.Cache, CultureInfo.CurrentCulture.NumberFormat.CurrencySymbol, e.Bounds, e.Appearance.Font, stringFormat);
stringFormat.Alignment = StringAlignment.Far;
e.Appearance.DrawString(e.Cache, valueText, e.Bounds, e.Appearance.Font, stringFormat);
}
}
這種方法有幾個缺點:
與手動繪製單元格的內容沒有被內置在Export and Printing系統
有必要計算文本寬度,以確保價值和貨幣符號不會相互重疊。爲此,您可以使用通過事件參數可用的CalcTextSizeInt對象的方法。 DevExpress的使用自己的文字渲染引擎,所以標準Graphics.MeasureString方法不是在這種情況下有用
+0
感謝您的幫助,我只是需要它的顯示目的。 – nadzdaim
相關問題
- 1. 對齊貨幣值
- 2. 將貨幣符號移至每個輸入的左側並保持對齊
- 3. 對齊小數貨幣的數組值
- 4. 右對齊貨幣字符串格式
- 5. 右對齊貨幣字符串(不帶符號)?
- 6. 左對齊醇號
- 7. iAP貨幣標籤的垂直對齊
- 8. Listview對齊十進制貨幣的貨幣
- 9. 右對齊貨幣文本使用jQuery
- 10. 如何將貨幣值(字符串)與右對齊
- 11. 如何正確對齊輸入字段並左對齊標籤?
- 12. 如何創建一個TD左對齊並且其兄弟右對齊的表?
- 13. 顯示柔性盒居中但左對齊項左左對齊
- 14. 左右對齊
- 15. 左右對齊
- 16. 在左邊對齊GridView的列值在左側
- 17. CSS左對齊,右對齊,並重復中間
- 18. 居中對齊容器並左對齊子元素
- 19. css/html左對齊和右對齊href
- 20. HTML左對齊,右對齊不工作
- 21. 右對齊和左對齊UITextView。
- 22. ul li對齊並在div的左側對齊
- 23. 如何在Bash中右對齊並左對齊文本字符串
- 24. 如何將右對齊或左對齊與「\ t」對齊?
- 25. Bootstrap 2列垂直對齊+ 1圖像對齊左對齊+ 1圖像對齊
- 26. 如何在貨幣管道中設置左右對齊角度2
- 27. CSS製作文本左對齊並同時對齊
- 28. 正確對齊div與左對齊div內聯?
- 29. Bootstrap導航欄對齊正確,但需要響應左對齊
- 30. 如何對齊貨幣的點在打印過程中
@Dmitry是,HTTPS://documentation.devexpress.com/#WindowsForms/DevExpressXtraGridColumnsGridColumn_DisplayFormattopic – SMW
如果你能問這個問題在https://www.devexpress.com/Support/Center/Question/ ,因爲它會幫助你, – SMW