轉(zhuǎn)帖|使用教程|編輯:我只采一朵|2014-09-16 09:46:11.000|閱讀 9492 次
概述:本文將為大家介紹如何在DevExpress GridControl中添加進(jìn)度條控件。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門(mén)軟控件火熱銷(xiāo)售中 >>
相關(guān)鏈接:
本文將為大家介紹如何在DevExpress GridControl中添加進(jìn)度條控件。
【DXperience Universal Suite下載】
首先可以使用 DevExpress GridControl 自帶的進(jìn)度條控件。
但是我要用一個(gè)方法來(lái)設(shè)置所有的單元格進(jìn)度,而不是每個(gè)單元格都要設(shè)置一遍,同時(shí)我想要根據(jù)進(jìn)度值不同,進(jìn)度條顯示不同的顏色。
那么就要自己手動(dòng)的編寫(xiě)代碼來(lái)完成了。
1 、繪制一個(gè)單元格進(jìn)度條形狀,當(dāng)進(jìn)度小于50%時(shí)顯示為紅色。
public void DrawProgressBar(DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { string s = e.CellValue as string; s = s.Substring(0, e.CellValue.ToString().Length - 1); decimal percent = Convert.ToDecimal(s); int width = (int)(100 * Math.Abs(percent /100 ) * e.Bounds.Width / 100); Rectangle rect = new Rectangle(e.Bounds.X, e.Bounds.Y, width, e.Bounds.Height); Brush b = Brushes.Green; if (percent < 50) { b = Brushes.Red; } e.Graphics.FillRectangle(b, rect); }
2、點(diǎn)擊 GridView 展開(kāi)觸發(fā)事件
private void gridView1_CustomDrawCell(object sender, DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { if (e.Column.FieldName == "CLASSPACE") { DrawProgressBar(e); e.Handled = true; DrawEditor(e); } }
3、上面兩段代碼其實(shí)效果已經(jīng)出來(lái)了,只不過(guò)有一些瑕疵,單元格只顯示數(shù)值,而不顯示進(jìn)度條(當(dāng)點(diǎn)擊單元格時(shí)數(shù)值會(huì)消失),那么需要我們?cè)賮?lái)手動(dòng)的編寫(xiě)一段代碼用來(lái)處理當(dāng)單元格觸發(fā)時(shí)一些操作。
private void DrawEditor(DevExpress.XtraGrid.Views.Base.RowCellCustomDrawEventArgs e) { GridCellInfo cell = e.Cell as GridCellInfo; Point offset = cell.CellValueRect.Location; BaseEditPainter pb = cell.ViewInfo.Painter as BaseEditPainter; AppearanceObject style = cell.ViewInfo.PaintAppearance; if (!offset.IsEmpty) cell.ViewInfo.Offset(offset.X, offset.Y); try { pb.Draw(new ControlGraphicsInfoArgs(cell.ViewInfo, e.Cache, cell.Bounds)); } finally { if(!offset.IsEmpty) { cell.ViewInfo.Offset(-offset.X, -offset.Y); } } }
同時(shí)將單元格設(shè)置為不可編輯狀態(tài)。
附最后顯示效果 :
出處://www.cnblogs.com/Albin/
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn