gigi78

sizable datagridview

Jan 23rd, 2021
1,103
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Public Class datagridviewRidimensionabile
  2.  
  3.     Inherits DataGridView
  4.  
  5.     Private layerFondoFinestra As Region
  6.     Private layerLatoFinestra As Region
  7.     Private origine As Point
  8.     Private selezioneLaterale As Boolean
  9.     Private selezioneFondo As Boolean
  10.  
  11.     Private Sub CreaLayer()
  12.  
  13.         layerFondoFinestra = New Region(New Rectangle(0, Me.Height - 5, Me.Width, 5))
  14.         layerLatoFinestra = New Region(New Rectangle(Me.Width - 5, 0, 5, Me.Height))
  15.  
  16.     End Sub
  17.  
  18.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  19.         MyBase.OnMouseDown(e)
  20.  
  21.         If e.Button = MouseButtons.Left Then
  22.             If layerFondoFinestra.IsVisible(e.Location) Then
  23.                 origine = e.Location
  24.                 selezioneFondo = True
  25.             End If
  26.             If layerLatoFinestra.IsVisible(e.Location) Then
  27.                 origine = e.Location
  28.                 selezioneLaterale = True
  29.             End If
  30.         End If
  31.  
  32.     End Sub
  33.  
  34.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  35.         MyBase.OnMouseUp(e)
  36.  
  37.         selezioneFondo = False
  38.         selezioneLaterale = False
  39.  
  40.     End Sub
  41.  
  42.     Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  43.         MyBase.OnMouseMove(e)
  44.  
  45.         Dim differenza As Point = origine - e.Location
  46.  
  47.         If selezioneLaterale = True Then
  48.             Me.Width -= differenza.X
  49.         End If
  50.         If selezioneFondo = True Then
  51.             Me.Height -= differenza.Y
  52.         End If
  53.  
  54.         If layerFondoFinestra.IsVisible(e.Location) Or layerLatoFinestra.IsVisible(e.Location) Then
  55.             Cursor = Cursors.Hand
  56.         Else
  57.             Cursor = Cursors.Default
  58.         End If
  59.  
  60.         origine = e.Location
  61.  
  62.     End Sub
  63.  
  64.     Protected Overrides Sub OnResize(e As EventArgs)
  65.         MyBase.OnResize(e)
  66.  
  67.         creaLayer()
  68.  
  69.     End Sub
  70.  
  71.     Protected Overrides Sub OnSizeChanged(e As EventArgs)
  72.         MyBase.OnSizeChanged(e)
  73.  
  74.         creaLayer()
  75.  
  76.     End Sub
  77.  
  78.     Protected Overrides Sub OnCreateControl()
  79.         MyBase.OnCreateControl()
  80.  
  81.         CreaLayer()
  82.  
  83.     End Sub
  84.  
  85. End Class
  86.  
RAW Paste Data