0Hawk0

Movie Preview Control

Dec 27th, 2014
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.02 KB | None | 0 0
  1. Public Class MoviePreview
  2.     Inherits Control
  3.  
  4.     Private G As Graphics
  5.  
  6.     Private _mouseOver As Boolean
  7.     Private Property MouseOver As Boolean
  8.         Get
  9.             Return _mouseOver
  10.         End Get
  11.         Set(value As Boolean)
  12.             If Not _mouseOver = value Then
  13.                 _mouseOver = value
  14.                 Invalidate()
  15.             End If
  16.         End Set
  17.     End Property
  18.  
  19.     Private _time As String
  20.     Public Property Time As String
  21.         Get
  22.             Return _time
  23.         End Get
  24.         Set(value As String)
  25.             _time = value
  26.             Invalidate()
  27.         End Set
  28.     End Property
  29.  
  30.     Private _timeFont As Font
  31.     Public Property TimeFont As Font
  32.         Get
  33.             Return _timeFont
  34.         End Get
  35.         Set(value As Font)
  36.             _timeFont = value
  37.             Invalidate()
  38.         End Set
  39.     End Property
  40.  
  41.     Sub New()
  42.  
  43.         SetStyle(DirectCast(139286, ControlStyles), True)
  44.         SetStyle(ControlStyles.Selectable, False)
  45.  
  46.         BackColor = Color.FromKnownColor(KnownColor.Control)
  47.         Cursor = Cursors.Hand
  48.         Font = New Font("Arial", 12)
  49.         Size = New Size(160, 200)
  50.  
  51.         TimeFont = New Font("Arial", 10)
  52.  
  53.         boundsRect = New Rectangle(0, 0, Width - 1, Height - 1)
  54.         titleRect = New Rectangle(0, 0, Width - 1, 40)
  55.         playRect = New Rectangle((boundsRect.Width / 2) - 40, (boundsRect.Height / 2) - 40, 80, 80)
  56.         playPoints = New Point() {New Point(playRect.X + 28, playRect.Y + 22), New Point(playRect.X + playRect.Width - 20, playRect.Y + (playRect.Height / 2)), New Point(playRect.X + 28, playRect.Y + playRect.Height - 22)}
  57.         timeRect = New Rectangle(0, Height - 27, Width - 1, 26)
  58.  
  59.         textBackBrush = New SolidBrush(Color.FromArgb(200, Color.DimGray))
  60.         textBrush = New SolidBrush(Color.WhiteSmoke)
  61.         playBackBrush = New SolidBrush(Color.FromArgb(200, Color.Black))
  62.         playBrush = New SolidBrush(Color.FromArgb(200, Color.Silver))
  63.  
  64.     End Sub
  65.  
  66.     Private boundsRect As Rectangle
  67.     Private titleRect, playRect, timeRect As Rectangle
  68.     Private playPoints As Point()
  69.  
  70.     Private textBackBrush, textBrush As SolidBrush
  71.     Private playBackBrush, playBrush As SolidBrush
  72.  
  73.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  74.  
  75.         G = e.Graphics
  76.  
  77.         G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
  78.         G.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
  79.         G.Clear(BackColor)
  80.  
  81.         If BackgroundImage IsNot Nothing Then G.DrawImage(BackgroundImage, boundsRect)
  82.  
  83.         If MouseOver Then
  84.  
  85.             G.FillRectangle(textBackBrush, titleRect)
  86.             G.DrawString(Text, Font, textBrush, 6, (titleRect.Height / 2) - (G.MeasureString(Text, Font).Height / 2) + 1)
  87.  
  88.             G.FillEllipse(playBackBrush, playRect)
  89.             G.FillPolygon(playBrush, playPoints)
  90.  
  91.             G.FillRectangle(textBackBrush, timeRect)
  92.             G.DrawString(Time, TimeFont, textBrush, 6, timeRect.Y + ((timeRect.Height / 2) - (G.MeasureString(Time, TimeFont).Height / 2)))
  93.  
  94.         End If
  95.  
  96.         G.DrawRectangle(Pens.Silver, boundsRect)
  97.  
  98.     End Sub
  99.  
  100.     Protected Overrides Sub OnSizeChanged(e As EventArgs)
  101.         boundsRect = New Rectangle(0, 0, Width - 1, Height - 1)
  102.         titleRect = New Rectangle(0, 0, Width - 1, 40)
  103.         playRect = New Rectangle((boundsRect.Width / 2) - 50, (boundsRect.Height / 2) - 50, 100, 100)
  104.         playPoints = New Point() {New Point(playRect.X + 28, playRect.Y + 22), New Point(playRect.X + playRect.Width - 20, playRect.Y + (playRect.Height / 2)), New Point(playRect.X + 28, playRect.Y + playRect.Height - 22)}
  105.         timeRect = New Rectangle(0, Height - 27, Width - 1, 26)
  106.         MyBase.OnSizeChanged(e)
  107.     End Sub
  108.  
  109.     Protected Overrides Sub OnMouseEnter(e As EventArgs)
  110.         MouseOver = True
  111.         MyBase.OnMouseEnter(e)
  112.     End Sub
  113.  
  114.     Protected Overrides Sub OnMouseLeave(e As EventArgs)
  115.         MouseOver = False
  116.         MyBase.OnMouseLeave(e)
  117.     End Sub
  118.  
  119. End Class
Add Comment
Please, Sign In to add comment