Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class MoviePreview
- Inherits Control
- Private G As Graphics
- Private _mouseOver As Boolean
- Private Property MouseOver As Boolean
- Get
- Return _mouseOver
- End Get
- Set(value As Boolean)
- If Not _mouseOver = value Then
- _mouseOver = value
- Invalidate()
- End If
- End Set
- End Property
- Private _time As String
- Public Property Time As String
- Get
- Return _time
- End Get
- Set(value As String)
- _time = value
- Invalidate()
- End Set
- End Property
- Private _timeFont As Font
- Public Property TimeFont As Font
- Get
- Return _timeFont
- End Get
- Set(value As Font)
- _timeFont = value
- Invalidate()
- End Set
- End Property
- Sub New()
- SetStyle(DirectCast(139286, ControlStyles), True)
- SetStyle(ControlStyles.Selectable, False)
- BackColor = Color.FromKnownColor(KnownColor.Control)
- Cursor = Cursors.Hand
- Font = New Font("Arial", 12)
- Size = New Size(160, 200)
- TimeFont = New Font("Arial", 10)
- boundsRect = New Rectangle(0, 0, Width - 1, Height - 1)
- titleRect = New Rectangle(0, 0, Width - 1, 40)
- playRect = New Rectangle((boundsRect.Width / 2) - 40, (boundsRect.Height / 2) - 40, 80, 80)
- 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)}
- timeRect = New Rectangle(0, Height - 27, Width - 1, 26)
- textBackBrush = New SolidBrush(Color.FromArgb(200, Color.DimGray))
- textBrush = New SolidBrush(Color.WhiteSmoke)
- playBackBrush = New SolidBrush(Color.FromArgb(200, Color.Black))
- playBrush = New SolidBrush(Color.FromArgb(200, Color.Silver))
- End Sub
- Private boundsRect As Rectangle
- Private titleRect, playRect, timeRect As Rectangle
- Private playPoints As Point()
- Private textBackBrush, textBrush As SolidBrush
- Private playBackBrush, playBrush As SolidBrush
- Protected Overrides Sub OnPaint(e As PaintEventArgs)
- G = e.Graphics
- G.SmoothingMode = Drawing2D.SmoothingMode.AntiAlias
- G.TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
- G.Clear(BackColor)
- If BackgroundImage IsNot Nothing Then G.DrawImage(BackgroundImage, boundsRect)
- If MouseOver Then
- G.FillRectangle(textBackBrush, titleRect)
- G.DrawString(Text, Font, textBrush, 6, (titleRect.Height / 2) - (G.MeasureString(Text, Font).Height / 2) + 1)
- G.FillEllipse(playBackBrush, playRect)
- G.FillPolygon(playBrush, playPoints)
- G.FillRectangle(textBackBrush, timeRect)
- G.DrawString(Time, TimeFont, textBrush, 6, timeRect.Y + ((timeRect.Height / 2) - (G.MeasureString(Time, TimeFont).Height / 2)))
- End If
- G.DrawRectangle(Pens.Silver, boundsRect)
- End Sub
- Protected Overrides Sub OnSizeChanged(e As EventArgs)
- boundsRect = New Rectangle(0, 0, Width - 1, Height - 1)
- titleRect = New Rectangle(0, 0, Width - 1, 40)
- playRect = New Rectangle((boundsRect.Width / 2) - 50, (boundsRect.Height / 2) - 50, 100, 100)
- 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)}
- timeRect = New Rectangle(0, Height - 27, Width - 1, 26)
- MyBase.OnSizeChanged(e)
- End Sub
- Protected Overrides Sub OnMouseEnter(e As EventArgs)
- MouseOver = True
- MyBase.OnMouseEnter(e)
- End Sub
- Protected Overrides Sub OnMouseLeave(e As EventArgs)
- MouseOver = False
- MyBase.OnMouseLeave(e)
- End Sub
- End Class
Add Comment
Please, Sign In to add comment