0
我使用一个DataGridView在Windows应用程序(.NET 3.5)表现出一些彩色条(基本上是“在时间任务”):Windowsforms:如何在DataGridView上绘制线条?
DataGridView 1 http://img195.imageshack.us/img195/879/datagridview1.png
我现在需要的是,以显示自定义图形“完成”栏取决于百分比值。这里是一个Photoshop处理图像:
DataGridView 2 http://img38.imageshack.us/img38/5615/datagridview2.png
任何暗示,我怎么能解决这个问题还是一个创造性的解决方案?
谢谢!
编辑:我不得不重绘电池,原因是其被“丢失”。这里是(VB.NET)代码的工作原理:
Private Sub DataGridView_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView.CellPainting
If e.ColumnIndex < FIRST_DATA_COLUMN OrElse e.RowIndex < 0 Then Return
If e.Value Is Nothing Then Return
Dim BarValue As Integer = DirectCast(e.Value, Integer)
If BarValue = 0 Then Return
Dim BackColorBrush As New SolidBrush(e.CellStyle.BackColor)
Dim GridBrush As New SolidBrush(Me.DataGridView.GridColor)
Dim GridLinePen As New Pen(GridBrush)
' -- Erase the cell
e.Graphics.FillRectangle(BackColorBrush, e.CellBounds)
' -- Draw the grid lines (only the right and bottom lines; DataGridView takes care of the others)
e.Graphics.DrawLine(GridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1)
e.Graphics.DrawLine(GridLinePen, e.CellBounds.Right - 1, e.CellBounds.Top, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1)
' -- Paint progress bar
Dim ProgressBarBrush As New SolidBrush(Color.Green)
Dim CellProgressBarRect As New Rectangle(e.CellBounds.X, e.CellBounds.Y + CELL_HEIGHT - PROGRESS_BAR_HEIGHT, BarValue, PROGRESS_BAR_HEIGHT)
e.Graphics.FillRectangle(ProgressBarBrush, CellProgressBarRect)
e.Handled = True
End Sub
是的,我想我必须这样做。一个问题:如果我做了一个自定义绘制钩入细胞绘画事件,我“失去”正常的布局,并不得不重新绘制细胞? – splattne 2009-07-13 07:53:47