Advertisement
netrosly

Ausologic Tabselector - GDI

Feb 1st, 2015
448
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 13.44 KB | None | 0 0
  1. 'Random Controls: Ausologic Tabselector
  2. 'By Nettro ;P please enjoy
  3. 'Tip: reminder to change the index of each item
  4. Imports System.Drawing.Drawing2D
  5. Imports System.ComponentModel
  6.  
  7. Public Class TabSelector
  8.     Inherits Panel
  9.     Property Selected As Selectt
  10.     Event ClickedParent()
  11.     Event ClickedStudent()
  12.     Event ClickedTeacher()
  13.     Dim InnerTeacher As Boolean = False
  14.     Dim InnerStudent As Boolean = False
  15.     Dim InnerParent As Boolean = False
  16.     Enum Selectt
  17.         Student
  18.         Teacher
  19.         parent
  20.     End Enum
  21.     Property SelectedItem As Integer = 0
  22.     Sub New()
  23.         Me.DoubleBuffered = True
  24.     End Sub
  25.  
  26.     Private Sub Tabcon_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
  27.         Dim locc As New Point
  28.         If e.Button = Windows.Forms.MouseButtons.Left Then
  29.             For Each itm As Item In _Items
  30.                 If itm.Index < 1 Then
  31.                     locc.X = 12
  32.                     locc.Y = 4
  33.                     If New Rectangle(locc.X, locc.Y, 32, 32).Contains(e.X, e.Y) Then
  34.                         SelectedItem = itm.Index
  35.                         Me.Refresh()
  36.                     End If
  37.                 Else
  38.                     locc.X = 64 * itm.Index
  39.                     locc.Y = 4
  40.                     If New Rectangle(locc.X, locc.Y, 32, 32).Contains(e.X, e.Y) Then
  41.                         SelectedItem = itm.Index
  42.                         Me.Refresh()
  43.                     End If
  44.                 End If
  45.             Next
  46.         End If
  47.     End Sub
  48.  
  49.     Private Sub Tabcon_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
  50.         Dim locc As New Point
  51.         For Each itm As Item In _Items
  52.             itm.Inner = False
  53.             If itm.Index < 1 Then
  54.                 locc.X = 12
  55.                 locc.Y = 4
  56.                 If New Rectangle(locc.X, locc.Y, 32, 32).Contains(e.X, e.Y) Then
  57.                     Cursor = Cursors.Hand
  58.                     itm.Inner = True
  59.                     Me.Refresh()
  60.                 End If
  61.             Else
  62.                 locc.X = 64 * itm.Index
  63.                 locc.Y = 4
  64.                 If New Rectangle(locc.X, locc.Y, 32, 32).Contains(e.X, e.Y) Or New Rectangle(12, 4, 32, 32).Contains(e.X, e.Y) Then
  65.                     Cursor = Cursors.Hand
  66.                     itm.Inner = True
  67.                     Me.Refresh()
  68.                 Else
  69.                     Cursor = Cursors.Arrow
  70.                     Me.Refresh()
  71.                 End If
  72.                 If New Rectangle(locc.X, locc.Y, 32, 32).Contains(e.X, e.Y) Then
  73.                     itm.Inner = True
  74.                 End If
  75.             End If
  76.         Next
  77.  
  78.     End Sub
  79.  
  80.     Private Sub Tabcon_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
  81.  
  82.         e.Graphics.SmoothingMode = SmoothingMode.AntiAlias
  83.         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(0, 140, 178)), New Rectangle(0, 0, Me.Width, Me.Height))
  84.         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(0, 171, 206)), New Rectangle(2, 0, Me.Width - 4, Me.Height - 3))
  85.         e.Graphics.FillRectangle(New SolidBrush(Color.FromArgb(0, 140, 178)), New Rectangle(3, 0, Me.Width - 6, Me.Height - 4))
  86.         For Each itm As Item In _Items
  87.             Dim locc As New Point
  88.             If itm.Index < 1 Then
  89.                 locc.X = 12
  90.                 locc.Y = 4
  91.                 itm.locx = locc.X
  92.                 itm.locy = locc.Y
  93.                 e.Graphics.DrawImage(itm.Image, New Rectangle(locc.X, locc.Y, 32, 32))
  94.                 If itm.usepic = False Then
  95.                     e.Graphics.DrawImage(itm.Image, New Rectangle(locc.X, locc.Y, 32, 32))
  96.                 Else
  97.                     Dim pic As New PictureBox
  98.                     If itm.refresh = False Then
  99.                         'pic.BackColor = Color.FromArgb(0, 140, 178)
  100.                         'pic.Size = New Size(32, 32)
  101.                         'pic.Location = locc
  102.                         'pic.LoadAsync(itm.URL)
  103.                         'pic.Name = "pic_" & itm.Index
  104.                         'pic.SizeMode = PictureBoxSizeMode.StretchImage
  105.                         'pic.InitialImage = My.Resources.loading
  106.                         'AddHandler pic.Paint, AddressOf pic_draw
  107.                         'Me.Controls.Add(pic)
  108.                         'Dim MyWebClient As New System.Net.WebClient
  109.                         'Dim ImageInBytes() As Byte = MyWebClient.DownloadData(itm.URL)
  110.                         'Dim ImageStream As New IO.MemoryStream(ImageInBytes)
  111.                         'e.Graphics.DrawImage(New System.Drawing.Bitmap(ImageStream), New Rectangle(12, 4, 32, 32))
  112.                     Else
  113.                         For Each pic2 As PictureBox In Me.Controls.OfType(Of PictureBox)()
  114.                             If pic2.Location = locc Then
  115.                                 pic2.Dispose()
  116.                             End If
  117.                         Next
  118.                         pic.BackColor = Color.FromArgb(0, 140, 178)
  119.                         pic.Size = New Size(32, 32)
  120.                         pic.Location = locc
  121.                         pic.LoadAsync(itm.URL)
  122.                         pic.Name = "pic_" & itm.Index
  123.                         pic.SizeMode = PictureBoxSizeMode.StretchImage
  124.                         AddHandler pic.Paint, AddressOf pic_draw
  125.                         Me.Controls.Add(pic)
  126.                         itm.refresh = False
  127.                         'Dim MyWebClient As New System.Net.WebClient
  128.                         'Dim ImageInBytes() As Byte = MyWebClient.DownloadData(itm.URL)
  129.                         'Dim ImageStream As New IO.MemoryStream(ImageInBytes)
  130.                         'e.Graphics.DrawImage(New System.Drawing.Bitmap(ImageStream), New Rectangle(12, 4, 32, 32))
  131.                     End If
  132.                 End If
  133.                 If SelectedItem = itm.Index Then
  134.                     Dim ptsArray2 As PointF() = {New Point(6, 0), New Point(46, 0), New Point(26, 12), New Point(6, 0)}
  135.                     e.Graphics.FillPolygon(New SolidBrush(Color.FromArgb(0, 92, 113)), ptsArray2)
  136.                     Dim ptsArray As PointF() = {New Point(6, -1), New Point(46, -1), New Point(26, 12), New Point(6, -1)}
  137.                     e.Graphics.FillPolygon(New SolidBrush(Color.FromArgb(240, 240, 240)), ptsArray)
  138.                 End If
  139.                 If itm.Inner = True Then
  140.                     e.Graphics.DrawString(itm.Text, New Font("Arial", 8, FontStyle.Regular), Brushes.White, New Rectangle(locc.X - 6, locc.Y + 28, 48, 12), New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  141.                 End If
  142.             Else
  143.                 locc.X = 64 * itm.Index
  144.                 locc.Y = 4
  145.                 itm.locx = locc.X
  146.                 itm.locy = locc.Y
  147.                 If itm.usepic = False Then
  148.                     e.Graphics.DrawImage(itm.Image, New Rectangle(locc.X, locc.Y, 32, 32))
  149.                 Else
  150.                     Dim pic As New PictureBox
  151.                     If itm.refresh = False Then
  152.                         'pic.BackColor = Color.FromArgb(0, 140, 178)
  153.                         'pic.Size = New Size(32, 32)
  154.                         'pic.Location = locc
  155.                         'pic.LoadAsync(itm.URL)
  156.                         'pic.Name = "pic_" & itm.Index
  157.                         'pic.SizeMode = PictureBoxSizeMode.StretchImage
  158.                         'pic.InitialImage = My.Resources.loading
  159.                         'AddHandler pic.Paint, AddressOf pic_draw
  160.                         'Me.Controls.Add(pic)
  161.                         'Dim MyWebClient As New System.Net.WebClient
  162.                         'Dim ImageInBytes() As Byte = MyWebClient.DownloadData(itm.URL)
  163.                         'Dim ImageStream As New IO.MemoryStream(ImageInBytes)
  164.                         'e.Graphics.DrawImage(New System.Drawing.Bitmap(ImageStream), New Rectangle(locc.X, locc.Y, 32, 32))
  165.                     Else
  166.                         For Each pic2 As PictureBox In Me.Controls.OfType(Of PictureBox)()
  167.                             If pic2.Location = locc Then
  168.                                 pic2.Dispose()
  169.                             End If
  170.                         Next
  171.                         pic.BackColor = Color.FromArgb(0, 140, 178)
  172.                         pic.Size = New Size(32, 32)
  173.                         pic.Location = locc
  174.                         pic.LoadAsync(itm.URL)
  175.                         pic.Name = "pic_" & itm.Index
  176.                         pic.SizeMode = PictureBoxSizeMode.StretchImage
  177.                         AddHandler pic.Paint, AddressOf pic_draw
  178.                         Me.Controls.Add(pic)
  179.                         'Dim MyWebClient As New System.Net.WebClient
  180.                         'Dim ImageInBytes() As Byte = MyWebClient.DownloadData(itm.URL)
  181.                         'Dim ImageStream As New IO.MemoryStream(ImageInBytes)
  182.                         'e.Graphics.DrawImage(New System.Drawing.Bitmap(ImageStream), New Rectangle(locc.X, locc.Y, 32, 32))
  183.                         'itm.refresh = False
  184.                     End If
  185.                 End If
  186.                 If SelectedItem = itm.Index Then
  187.                     Dim ptsArray2 As PointF() = {New Point(locc.X - 6, 0), New Point(locc.X + 38, 0), New Point(locc.X + 16, 12), New Point(locc.X - 6, 0)}
  188.                     e.Graphics.FillPolygon(New SolidBrush(Color.FromArgb(0, 92, 113)), ptsArray2)
  189.                     Dim ptsArray As PointF() = {New Point(locc.X - 6, -1), New Point(locc.X + 38, -1), New Point(locc.X + 16, 12), New Point(locc.X - 6, -1)}
  190.                     e.Graphics.FillPolygon(New SolidBrush(Color.FromArgb(240, 240, 240)), ptsArray)
  191.                 End If
  192.                 If itm.Inner = True Then
  193.                     e.Graphics.DrawString(itm.Text, New Font("Arial", 8, FontStyle.Regular), Brushes.White, New Rectangle(locc.X - 12, locc.Y + 28, locc.X, 12), New StringFormat With {.Alignment = StringAlignment.Center, .LineAlignment = StringAlignment.Center})
  194.                 End If
  195.             End If
  196.  
  197.         Next
  198.     End Sub
  199.  
  200. #Region "Itemss"
  201.     Public Class ItemCollection
  202.         Inherits List(Of Item)
  203.         Private Parent As TabSelector
  204.         Public Sub New(Parent As TabSelector)
  205.             Me.Parent = Parent
  206.  
  207.         End Sub
  208.         Public Shadows Sub Add(Item As Item)
  209.             MyBase.Add(Item)
  210.             'Parent.InvalidateScroll()
  211.         End Sub
  212.         Public Shadows Sub AddRange(Range As List(Of Item))
  213.             MyBase.AddRange(Range)
  214.             'Parent.InvalidateScroll()
  215.         End Sub
  216.         Public Shadows Sub Clear()
  217.             MyBase.Clear()
  218.             'Parent.InvalidateScroll()
  219.         End Sub
  220.         Public Shadows Sub Remove(Item As Item)
  221.             MyBase.Remove(Item)
  222.             'Parent.InvalidateScroll()
  223.         End Sub
  224.         Public Shadows Sub RemoveAt(Index As Integer)
  225.             MyBase.RemoveAt(Index)
  226.             'Parent.InvalidateScroll()
  227.         End Sub
  228.         Public Shadows Sub RemoveAll(Predicate As System.Predicate(Of Item))
  229.             MyBase.RemoveAll(Predicate)
  230.             'Parent.InvalidateScroll()
  231.         End Sub
  232.         Public Shadows Sub RemoveRange(Index As Integer, Count As Integer)
  233.             MyBase.RemoveRange(Index, Count)
  234.             'Parent.InvalidateScroll()
  235.         End Sub
  236.  
  237.     End Class
  238.     Public Class Item
  239.         Property Text As String
  240.         Property Index As Integer = 0
  241.         Property locy As Integer = 0
  242.         Property locx As Integer = 0
  243.         Property Image As Image
  244.         Property Inner As Boolean = False
  245.         Property refresh As Boolean = True
  246.         Property usepic As Boolean = False
  247.         Property URL As String = ""
  248.         Property Selected As Boolean = False
  249.         Protected UniqueId As Guid
  250.         Sub New()
  251.             UniqueId = Guid.NewGuid()
  252.         End Sub
  253.         Public Overrides Function ToString() As String
  254.             Return Text
  255.         End Function
  256.  
  257.         Public Overrides Function Equals(obj As Object) As Boolean
  258.             If TypeOf obj Is Item Then
  259.                 Return (DirectCast(obj, Item).UniqueId = UniqueId)
  260.             End If
  261.             Return False
  262.         End Function
  263.  
  264.     End Class
  265.     Public _Items As New ItemCollection(Me)
  266.     <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  267.     Public Property Items As ItemCollection
  268.         Get
  269.             Return _Items
  270.         End Get
  271.         Set(ByVal value As ItemCollection)
  272.             _Items = value
  273.         End Set
  274.     End Property
  275. #End Region
  276.  
  277.     Private Sub pic_draw(sender As Object, e As PaintEventArgs)
  278.         'For Each pic As PictureBox In Me.Controls.OfType(Of PictureBox)()
  279.         '    Dim temp As String = pic.Name.Split("_").Last
  280.         '    FindForm.Text = temp
  281.         '    If temp = SelectedItem Then
  282.         '        AddHandler pic.Paint, AddressOf draw1
  283.         '        pic.Refresh()
  284.         '    End If
  285.         'Next
  286.     End Sub
  287.  
  288.     Private Sub draw1(sender As Object, e As PaintEventArgs)
  289.         'e.Graphics.SmoothingMode = SmoothingMode.HighQuality
  290.         'Dim ptsArray2 As PointF() = {New Point(1, 0), New Point(31, 0), New Point(16, 12), New Point(1, 0)}
  291.         '            e.Graphics.FillPolygon(New SolidBrush(Color.FromArgb(0, 92, 113)), ptsArray2)
  292.         'Dim ptsArray As PointF() = {New Point(1, -1), New Point(31, -1), New Point(16, 12), New Point(1, -1)}
  293.         '            e.Graphics.FillPolygon(New SolidBrush(Color.FromArgb(240, 240, 240)), ptsArray)
  294.  
  295.     End Sub
  296.  
  297. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement