Õâ¶Î´úÂëÑÝʾÁËÔÚDataGridViewÖÐÔö¼ÓÒ»¸öÁÐÏÔʾ½ø¶ÈÌõ£¬ÔÚÅúÁ¿ÉÏ´«ºÍÏÂÔØµÄʱºò³£Óõ½¡£ ½ø¶ÈÌõµÄ±ä»¯È磺 DataGridview.row(x).cell(x).value=50 ¸Ä±äËûµÄÖµ¾ÍÊÇÁË¡£
±êÇ©£º <ÎÞ>
´úÂëÆ¬¶Î(4)
[´úÂë] [ASP/Basic]´úÂë
002 |
Imports System.Drawing |
003 |
Imports System.Windows.Forms |
004 |
Public Class DataGridViewPrassBar |
005 |
Public Class DataGridViewProgressBarColumn |
006 |
Inherits DataGridViewTextBoxColumn |
009 |
Me .CellTemplate = New DataGridViewProgressBarCell() |
012 |
Public Overrides Property CellTemplate() As DataGridViewCell |
014 |
Return MyBase .CellTemplate |
016 |
Set ( ByVal value As DataGridViewCell) |
017 |
If Not TypeOf value Is DataGridViewProgressBarCell Then |
018 |
Throw New InvalidCastException( "DataGridViewProgressBarCell¥ª¥Ö¥¸¥§¥¯¥È¤ò" + "Ö¸¶¨¤·¤Æ¤¯¤À¤µ¤¤¡£" ) |
020 |
MyBase .CellTemplate = value |
027 |
Public Property Maximum() As Integer |
029 |
Return CType ( Me .CellTemplate,DataGridViewProgressBarCell).Maximum |
031 |
Set ( ByVal value As Integer ) |
032 |
If Me .Maximum = value Then |
035 |
CType ( Me .CellTemplate,DataGridViewProgressBarCell).Maximum = value |
036 |
If Me .DataGridView Is Nothing Then |
039 |
Dim rowCount As Integer = Me .DataGridView.RowCount |
041 |
For i = 0 To rowCount - 1 |
042 |
Dim r As DataGridViewRow = Me .DataGridView.Rows.SharedRow(i) |
043 |
CType (r.Cells( Me .Index),DataGridViewProgressBarCell).Maximum = value |
050 |
Public Property Mimimum() As Integer |
052 |
Return CType ( Me .CellTemplate,DataGridViewProgressBarCell).Mimimum |
054 |
Set ( ByVal value As Integer ) |
056 |
If Me .Mimimum = value Then |
062 |
CType ( Me .CellTemplate,DataGridViewProgressBarCell).Mimimum = value |
064 |
If Me .DataGridView Is Nothing Then |
069 |
Dim rowCount As Integer = Me .DataGridView.RowCount |
071 |
For i = 0 To rowCount - 1 |
072 |
Dim r As DataGridViewRow = Me .DataGridView.Rows.SharedRow(i) |
073 |
CType (r.Cells( Me .Index),DataGridViewProgressBarCell).Mimimum = value |
082 |
Public Class DataGridViewProgressBarCell |
083 |
Inherits DataGridViewTextBoxCell |
086 |
Me .maximumValue = 100 |
089 |
Private maximumValue As Integer |
091 |
Public Property Maximum() As Integer |
093 |
Return Me .maximumValue |
095 |
Set ( ByVal value As Integer ) |
096 |
Me .maximumValue = value |
102 |
Private mimimumValue As Integer |
104 |
Public Property Mimimum() As Integer |
106 |
Return Me .mimimumValue |
108 |
Set ( ByVal value As Integer ) |
109 |
Me .mimimumValue = value |
115 |
Public Overrides ReadOnly Property ValueType() As Type |
119 |
Return GetType ( Integer ) |
127 |
Public Overrides ReadOnly Property DefaultNewRowValue() As Object |
139 |
Public Overrides Function Clone() As Object |
140 |
Dim cell As DataGridViewProgressBarCell = CType ( MyBase .Clone(),DataGridViewProgressBarCell) |
141 |
cell.Maximum = Me .Maximum |
142 |
cell.Mimimum = Me .Mimimum |
148 |
Protected Overrides Sub Paint( ByVal graphics As Graphics, ByVal clipBounds As Rectangle, ByVal cellBounds As Rectangle, ByVal rowIndex As Integer , ByVal cellState As DataGridViewElementStates, ByVal value As Object , ByVal formattedValue As Object , ByVal errorText As String , ByVal cellStyle As DataGridViewCellStyle, ByVal advancedBorderStyle As DataGridViewAdvancedBorderStyle, ByVal paintParts As DataGridViewPaintParts) |
149 |
Dim intValue As Integer = 0 |
150 |
If TypeOf value Is Integer Then |
151 |
intValue = CInt (value) |
153 |
If intValue < Me .mimimumValue Then |
154 |
intValue = Me .mimimumValue |
157 |
If intValue > Me .maximumValue Then |
158 |
intValue = Me .maximumValue |
161 |
Dim rate As Double = CDbl (intValue - Me .mimimumValue) / ( Me .maximumValue - Me .mimimumValue) |
162 |
If (paintParts And DataGridViewPaintParts.Border) = DataGridViewPaintParts.Border Then |
163 |
Me .PaintBorder(graphics,clipBounds,cellBounds,cellStyle,advancedBorderStyle) |
165 |
Dim borderRect As Rectangle = Me .BorderWidths(advancedBorderStyle) |
166 |
Dim paintRect As New Rectangle(cellBounds.Left + borderRect.Left,cellBounds.Top + borderRect.Top,cellBounds.Width - borderRect.Right,cellBounds.Height - borderRect.Bottom) |
167 |
Dim isSelected As Boolean = ((cellState And DataGridViewElementStates.Selected) = DataGridViewElementStates.Selected) |
169 |
If isSelected AndAlso (paintParts And DataGridViewPaintParts.SelectionBackground) = DataGridViewPaintParts.SelectionBackground Then |
170 |
bkColor = cellStyle.SelectionBackColor |
172 |
bkColor = cellStyle.BackColor |
174 |
If (paintParts And DataGridViewPaintParts.Background) = DataGridViewPaintParts.Background Then |
175 |
Dim backBrush As New SolidBrush(bkColor) |
177 |
graphics.FillRectangle(backBrush,paintRect) |
182 |
paintRect.Offset(cellStyle.Padding.Right,cellStyle.Padding.Top) |
183 |
paintRect.Width -= cellStyle.Padding.Horizontal |
184 |
paintRect.Height -= cellStyle.Padding.Vertical |
185 |
If (paintParts And DataGridViewPaintParts.ContentForeground) = DataGridViewPaintParts.ContentForeground Then |
186 |
If ProgressBarRenderer.IsSupported Then |
187 |
ProgressBarRenderer.DrawHorizontalBar(graphics,paintRect) |
188 |
Dim barBounds As New Rectangle(paintRect.Left + 3,paintRect.Top + 3,paintRect.Width - 4,paintRect.Height - 6) |
189 |
barBounds.Width = CInt (Math.Round((barBounds.Width * rate))) |
190 |
ProgressBarRenderer.DrawHorizontalChunks(graphics,barBounds) |
192 |
graphics.FillRectangle(Brushes.White,paintRect) |
193 |
graphics.DrawRectangle(Pens.Black,paintRect) |
194 |
Dim barBounds As New Rectangle(paintRect.Left + 1,paintRect.Top + 1,paintRect.Width - 1,paintRect.Height - 1) |
195 |
barBounds.Width = CInt (Math.Round((barBounds.Width * rate))) |
196 |
graphics.FillRectangle(Brushes.Blue,barBounds) |
199 |
If Me .DataGridView.CurrentCellAddress.X = Me .ColumnIndex AndAlso Me .DataGridView.CurrentCellAddress.Y = Me .RowIndex AndAlso (paintParts And DataGridViewPaintParts.Focus) = DataGridViewPaintParts.Focus AndAlso Me .DataGridView.Focused Then |
200 |
Dim focusRect As Rectangle = paintRect |
201 |
focusRect.Inflate(-3,-3) |
202 |
ControlPaint.DrawFocusRectangle(graphics,focusRect) |
204 |
If (paintParts And DataGridViewPaintParts.ContentForeground) = DataGridViewPaintParts.ContentForeground Then |
205 |
Dim txt As String = String .Format( "{0}%" ,Math.Round((rate * 100))) |
206 |
Dim flags As TextFormatFlags = TextFormatFlags.HorizontalCenter Or TextFormatFlags.VerticalCenter |
207 |
Dim fColor As Color = cellStyle.ForeColor |
208 |
paintRect.Inflate(-2,-2) |
209 |
TextRenderer.DrawText(graphics,txt,cellStyle.Font,paintRect,fColor,flags) |
212 |
If (paintParts And DataGridViewPaintParts.ErrorIcon) = DataGridViewPaintParts.ErrorIcon AndAlso Me .DataGridView.ShowCellErrors AndAlso Not String .IsNullOrEmpty(errorText) Then |
213 |
Dim iconBounds As Rectangle = Me .GetErrorIconBounds(graphics,rowIndex) |
215 |
iconBounds.Offset(cellBounds.X,cellBounds.Y) |
217 |
Me .PaintErrorIcon(graphics,iconBounds,errorText) |
231 |
Dim pbColumn As New DataGridViewPrassBar.DataGridViewProgressBarColumn() |
232 |
pbColumn.DataPropertyName = "Column1" |
233 |
DataGridView1.Columns.Add(pbColumn) |
[´úÂë] [ASP/Basic]´úÂë
002 |
Imports System.Drawing |
003 |
Imports System.Windows.Forms |
004 |
Public Class DataGridViewPrassBar |
005 |
Public Class DataGridViewProgressBarColumn |
006 |
Inherits DataGridViewTextBoxColumn |
009 |
Me .CellTemplate = New DataGridViewProgressBarCell() |
012 |
Public Overrides Property CellTemplate() As DataGridViewCell |
014 |
Return MyBase .CellTemplate |
016 |
Set ( ByVal value As DataGridViewCell) |
017 |
If Not TypeOf value Is DataGridViewProgressBarCell Then |
018 |
Throw New InvalidCastException( "DataGridViewProgressBarCell¥ª¥Ö¥¸¥§¥¯¥È¤ò" + "Ö¸¶¨¤·¤Æ¤¯¤À¤µ¤¤¡£" ) |
020 |
MyBase .CellTemplate = value |
027 |
Public Property Maximum() As Integer |
029 |
Return CType ( Me .CellTemplate,errorText) |
231 |
Dim pbColumn As New DataGridViewPrassBar.DataGridViewProgressBarColumn() |
232 |
pbColumn.DataPropertyName = "Column1" |
233 |
DataGridView1.Columns.Add(pbColumn) |
£¨±à¼£ºÀî´óͬ£©
¡¾ÉùÃ÷¡¿±¾Õ¾ÄÚÈݾùÀ´×ÔÍøÂ磬ÆäÏà¹ØÑÔÂÛ½ö´ú±í×÷Õ߸öÈ˹۵㣬²»´ú±í±¾Õ¾Á¢³¡¡£ÈôÎÞÒâÇÖ·¸µ½ÄúµÄȨÀû£¬Ç뼰ʱÓëÁªÏµÕ¾³¤É¾³ýÏà¹ØÄÚÈÝ!
|