Advertisement
netrosly

Shelf/GridView - GDI Control

Mar 21st, 2015
581
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 7.67 KB | None | 0 0
  1. Imports System.ComponentModel
  2. Imports System.Drawing.Drawing2D
  3.  
  4. Public Class GridView
  5.     Inherits Panel
  6.  
  7.     Property ItemWidth As Integer = 141
  8.     Property ItemHeight As Integer = 201
  9.     Property Row As Integer = 8
  10.     Property Column As Integer = 1000
  11.     Property Spacing As Integer = 20
  12.     Property FRefresh As Boolean = True
  13.     Event Clicked(URL As String)
  14.    
  15.     Sub New()
  16.         Me.DoubleBuffered = True
  17.     End Sub
  18.  
  19.     Dim pic As New Pict
  20.     Private Sub GridView_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
  21.         If FRefresh = True Then
  22.             For i3 As Integer = 0 To Row
  23.                 For Each pic As Pict In Me.Controls.OfType(Of Pict)()
  24.                     pic.Dispose()
  25.                 Next
  26.             Next
  27.             Dim NewLoc As New Point
  28.             Dim i As Integer = 0
  29.             For CurrCol As Integer = 0 To Column
  30.                 For CurrRow As Integer = 0 To Row
  31.                     i += 1
  32.                     For Each itm As Item In Items
  33.                         If itm.OrderNumber = i Then
  34.                             NewLoc.X = CurrRow * (ItemWidth + Spacing)
  35.                             NewLoc.Y = CurrCol * (ItemHeight + Spacing)
  36.                             itm.Locate = NewLoc
  37.                             pic = New Pict
  38.                             pic.ItemHeight = ItemHeight
  39.                             pic.ItemWidth = ItemWidth
  40.                             pic.Show_Name = itm.Text
  41.                             pic.Name = itm.OrderNumber.ToString
  42.                             pic.Location = NewLoc
  43.                             pic.Parent = FindForm.Parent
  44.                             pic.Size = New Size(ItemWidth, ItemHeight)
  45.                             pic.SizeMode = PictureBoxSizeMode.StretchImage
  46.                             AddHandler pic.MouseMove, AddressOf pic_MM
  47.                             AddHandler pic.MouseM, AddressOf pic_MC
  48.                             pic.LoadAsync(itm.URL_LINK)
  49.                             Me.Controls.Add(pic)
  50.                         End If
  51.                     Next
  52.                 Next
  53.             Next
  54.             FRefresh = False
  55.         End If
  56.     End Sub
  57.  
  58.     Private Sub pic_MM(sender As Object, e As MouseEventArgs)
  59.         If New Rectangle(ItemWidth / 2 - 30, ItemHeight / 2 - 30, 60, 60).Contains(e.X, e.Y) Then
  60.             Cursor = Cursors.Hand
  61.         Else
  62.             Cursor = Cursors.Arrow
  63.         End If
  64.     End Sub
  65.     Private Sub pic_MC(Mouselocation As Point, pic As String, e As MouseEventArgs)
  66.         If e.Button = Windows.Forms.MouseButtons.Left Then
  67.             For Each itm As Item In Items
  68.                 If pic = itm.OrderNumber Then
  69.                     RaiseEvent Clicked(itm.ShowLink)
  70.                 End If
  71.             Next
  72.         End If
  73.     End Sub
  74. #Region "Item Collection"
  75.     Public Class ItemCollection
  76.         Inherits List(Of Item)
  77.         Public Parent As GridView
  78.         Public Sub New(Parent As GridView)
  79.             Me.Parent = Parent
  80.         End Sub
  81.         Public Shadows Sub Add(Item As Item)
  82.             MyBase.Add(Item)
  83.             ' Parent.InvalidateScroll()
  84.         End Sub
  85.         Public Shadows Sub AddRange(Range As List(Of Item))
  86.             MyBase.AddRange(Range)
  87.             ' Parent.InvalidateScroll()
  88.         End Sub
  89.         Public Shadows Sub Clear()
  90.             MyBase.Clear()
  91.             ' Parent.InvalidateScroll()
  92.         End Sub
  93.         Public Shadows Sub Remove(Item As Item)
  94.             MyBase.Remove(Item)
  95.             ' Parent.InvalidateScroll()
  96.         End Sub
  97.         Public Shadows Sub RemoveAt(Index As Integer)
  98.             MyBase.RemoveAt(Index)
  99.             'Parent.InvalidateScroll()
  100.         End Sub
  101.         Public Shadows Sub RemoveAll(Predicate As System.Predicate(Of Item))
  102.             MyBase.RemoveAll(Predicate)
  103.             '  Parent.InvalidateScroll()
  104.         End Sub
  105.         Public Shadows Sub RemoveRange(Index As Integer, Count As Integer)
  106.             MyBase.RemoveRange(Index, Count)
  107.             '  Parent.InvalidateScroll()
  108.         End Sub
  109.  
  110.     End Class
  111.     Public Class Item
  112.         Property Text As String
  113.         Property OrderNumber As Integer
  114.         Property MouseEntered As Boolean = False
  115.         Public Type As String = "None"
  116.         Property PictureLink As Boolean = False
  117.         Property URL_LINK As String = "http://i.imgur.com/blkrqBo.gif"
  118.         Property ShowLink As String = "None"
  119.         Property Locate As Point = New Point(0, 0)
  120.         Protected UniqueId As Guid
  121.         Sub New()
  122.             UniqueId = Guid.NewGuid()
  123.         End Sub
  124.         Public Overrides Function ToString() As String
  125.             Return Text
  126.         End Function
  127.  
  128.         Public Overrides Function Equals(obj As Object) As Boolean
  129.             If TypeOf obj Is Item Then
  130.                 Return (DirectCast(obj, Item).UniqueId = UniqueId)
  131.             End If
  132.             Return False
  133.         End Function
  134.  
  135.     End Class
  136.     Public _Items As New ItemCollection(Me)
  137.     <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  138.     Public Property Items As ItemCollection
  139.         Get
  140.             Return _Items
  141.         End Get
  142.         Set(ByVal value As ItemCollection)
  143.             _Items = value
  144.         End Set
  145.     End Property
  146. #End Region
  147. #Region "Custom Picturebox"
  148.     Public Class Pict
  149.         Inherits PictureBox
  150.         Property MouseLoc As Point
  151.         Property ItemWidth As Integer = 151
  152.         Property Show_Name As String
  153.         Property inner = False
  154.         Property ItemHeight As Integer = 201
  155.         Event MouseM(Mouselocation As Point, pic As String, e As MouseEventArgs)
  156.  
  157.         Private Sub Pict_MouseClick(sender As Object, e As MouseEventArgs) Handles Me.MouseClick
  158.             If e.Button = Windows.Forms.MouseButtons.Left Then
  159.  
  160.                 If New Rectangle(ItemWidth / 2 - 30, ItemHeight / 2 - 30, 60, 60).Contains(e.X, e.Y) Then
  161.                     RaiseEvent MouseM(MouseLoc, Me.Name, e)
  162.                 End If
  163.             End If
  164.         End Sub
  165.  
  166.         Private Sub Pict_MouseEnter(sender As Object, e As EventArgs) Handles Me.MouseEnter
  167.             inner = True
  168.             Me.Refresh()
  169.         End Sub
  170.  
  171.         Private Sub Pict_MouseLeave(sender As Object, e As EventArgs) Handles Me.MouseLeave
  172.             inner = False
  173.             Me.Refresh()
  174.         End Sub
  175.         Private Sub Pict_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
  176.             MouseLoc = e.Location
  177.         End Sub
  178.  
  179.         Private Sub Pict_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
  180.             e.Graphics.DrawRectangle(Pens.Black, New Rectangle(0, 0, ItemWidth - 2, ItemHeight - 2))
  181.             If inner = True Then
  182.                 e.Graphics.DrawEllipse(Pens.Black, New Rectangle(ItemWidth / 2 - 30, ItemHeight / 2 - 30, 60, 60))
  183.                 e.Graphics.FillEllipse(New SolidBrush(Color.FromArgb(150, Color.Black)), New Rectangle(ItemWidth / 2 - 30, ItemHeight / 2 - 30, 60, 60))
  184.                 e.Graphics.DrawString("4", New Font("Webdings", 46, FontStyle.Regular), Brushes.White, New Rectangle(ItemWidth / 2 - 26, ItemHeight / 2 - 27, 60, 60), New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  185.                 e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(120, 0, 0, 0)), New Rectangle(0, ItemHeight - 50, ItemWidth, 50))
  186.                 e.Graphics.DrawString(Show_Name, New Font("Arial", 11, FontStyle.Regular), Brushes.White, New Rectangle(0, ItemHeight - 50, ItemWidth, 50), New StringFormat() With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  187.             End If
  188.         End Sub
  189.     End Class
  190. #End Region
  191. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement