1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
| Private Sub DGV_Work_CellLeave(ByVal sender As Object, ByVal e As DataGridViewCellEventArgs) Handles DGV_Work.CellLeave
DGV_Work.Invalidate()
End Sub
Private Sub DGV_Work_RowPaint(ByVal sender As Object, ByVal e As DataGridViewRowPostPaintEventArgs) Handles DGV_Work.RowPostPaint
RectCellSelect()
End Sub
Private Sub RectCellSelect()
If IsNothing(DGV_Work.CurrentRow) Then Return
Using p As Pen = New Pen(Color.FromArgb(0, 176, 240), 3)
Using myGraphics As Graphics = Graphics.FromHwnd(DGV_Work.Handle)
Dim Rect, RectRow As Rectangle
Dim SelCol, SelRow, TmpWidth, TmpHeight As Int16
SelCol = DGV_Work.ColumnCount
SelRow = DGV_Work.RowCount
'Détermination du plus petit index cellule
For Each Cell As DataGridViewCell In DGV_Work.SelectedCells
If Cell.ColumnIndex < SelCol Then SelCol = Cell.ColumnIndex
If Cell.RowIndex < SelRow Then SelRow = Cell.RowIndex
Next
'Taille de la zone sélectionné
For Each Cell As DataGridViewCell In DGV_Work.SelectedCells
If Cell.ColumnIndex = SelCol Then
TmpHeight += DGV_Work.Rows(Cell.RowIndex).Height
End If
If Cell.RowIndex = SelRow And DGV_Work.Columns(Cell.ColumnIndex).Visible = True Then
TmpWidth += DGV_Work.Columns(Cell.ColumnIndex).Width
End If
Next
'Récupération des X/Y de la zone pointé
Rect = DGV_Work.GetCellDisplayRectangle(SelCol, SelRow, False)
If Rect.X = 0 And Rect.Y = 0 Then
RectRow = DGV_Work.GetRowDisplayRectangle(SelRow, False)
RectRow.X += DGV_Work.RowHeadersWidth
End If
'Calcul offset rectangle
Rect.X += RectRow.X - 1
Rect.Y += RectRow.Y - 1
Rect.Width = TmpWidth + 1
Rect.Height = TmpHeight + 1
'Dessine rectangle bleu
myGraphics.DrawRectangle(p, Rect)
'Calcul offset 2éme rectangle dans le premier
p.Color = Color.White
p.Width = 1
Rect.X += 2
Rect.Y += 2
Rect.Width -= 4
Rect.Height -= 4
'Dessine 2éme rectangle
myGraphics.DrawRectangle(p, Rect)
End Using
End Using
End Sub |
Partager