ibennz

SideShow

May 5th, 2014
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.93 KB | None | 0 0
  1. Class SideShow
  2.     'Creator: ibennz
  3.     'Version: 1.0 (sketch)
  4.     Inherits Control
  5.     Sub New()
  6.         Size = New Size(120, 23)
  7.     End Sub
  8.  
  9.    Private _items As New List(Of itemd)
  10.     <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  11.     Public Property Items As itemd()
  12.         Get
  13.             Return _items.ToArray
  14.         End Get
  15.         Set(value As itemd())
  16.             _items = New List(Of itemd)(value)
  17.         End Set
  18.     End Property
  19.     Protected Overrides Sub OnPaint(e As System.Windows.Forms.PaintEventArgs)
  20.         Dim G As Graphics = e.Graphics
  21.         G.Clear(BackColor)
  22.         G.SmoothingMode = SmoothingMode.HighQuality
  23.  
  24.         'right arrow
  25.         G.DrawLine(Pens.Red, New Point(Width - 9, 5), New Point(Width - 6, (Height / 2) - 1))
  26.         G.DrawLine(Pens.Red, New Point(Width - 9, 15), New Point(Width - 6, (Height / 2) - 1))
  27.  
  28.         'left arrow
  29.         G.DrawLine(Pens.Red, New Point(9, 5), New Point(6, (Height / 2) - 1))
  30.         G.DrawLine(Pens.Red, New Point(9, 15), New Point(6, (Height / 2) - 1))
  31.  
  32.  
  33.         If Not (IsNothing(_items)) Then
  34.             For Each i As itemd In _items
  35.                 Dim tData As String = GetItem(_indx).data
  36.  
  37.                 Dim ms As Integer = G.MeasureString(tData, Font, Width, StringFormat.GenericTypographic).Width
  38.                 G.DrawString(tData, Font, Brushes.Black, New PointF((Width / 2) - (ms / 2), 5))
  39.  
  40.             Next
  41.         End If
  42.  
  43.  
  44.         Dim GP1 As GraphicsPath = RoundRec(New Rectangle(0, 0, Width - 1, Height - 1), 5)
  45.         G.DrawPath(Pens.Red, GP1)
  46.         MyBase.OnPaint(e)
  47.     End Sub
  48.     Private _indx As Integer = 0
  49.     Protected Overrides Sub OnMouseDown(e As System.Windows.Forms.MouseEventArgs)
  50.  
  51.         If e.X <= 14 Then
  52.             _indx -= 1
  53.         End If
  54.         If e.X >= 104 Then
  55.             _indx += 1
  56.         End If
  57.         Invalidate()
  58.         MyBase.OnMouseDown(e)
  59.     End Sub
  60.     Public Function RoundRec(ByVal Rectangle As Rectangle, ByVal Curve As Integer) As GraphicsPath
  61.         Dim P As GraphicsPath = New GraphicsPath()
  62.         Dim ArcRectangleWidth As Integer = Curve * 2
  63.         P.AddArc(New Rectangle(Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -180, 90)
  64.         P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), -90, 90)
  65.         P.AddArc(New Rectangle(Rectangle.Width - ArcRectangleWidth + Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 0, 90)
  66.         P.AddArc(New Rectangle(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y, ArcRectangleWidth, ArcRectangleWidth), 90, 90)
  67.         P.AddLine(New Point(Rectangle.X, Rectangle.Height - ArcRectangleWidth + Rectangle.Y), New Point(Rectangle.X, Curve + Rectangle.Y))
  68.         Return P
  69.     End Function
  70.  
  71.  
  72.     Public Function GetItem(ByVal index As Integer) As itemd
  73.  
  74.         For Each i As itemd In _items
  75.             If i.Index = index Then
  76.                 Return i
  77.             End If
  78.         Next
  79.         If index >= _items.Count - 1 Then
  80.             _indx = 0
  81.             Return _items(0)
  82.         Else
  83.             _indx = _items.Count - 1
  84.         End If
  85.  
  86.         Return _items(_indx)
  87.     End Function
  88.  
  89.  
  90.     Public Class itemd
  91.  
  92.         Private _data As String
  93.         Public Property data() As String
  94.             Get
  95.                 Return _data
  96.             End Get
  97.  
  98.             Set(value As String)
  99.                 _data = value
  100.             End Set
  101.         End Property
  102.         Public Overrides Function ToString() As String
  103.             Return data
  104.         End Function
  105.         Private _index As Integer = 0
  106.         Public Property Index() As Integer
  107.             Get
  108.                 Return _index
  109.             End Get
  110.             Set(value As Integer)
  111.                 _index = value
  112.             End Set
  113.         End Property
  114.     End Class
  115. End Class
Advertisement
Add Comment
Please, Sign In to add comment