Advertisement
netrosly

PokeForm

Aug 1st, 2016
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 5.41 KB | None | 0 0
  1. Imports System.Drawing.Drawing2D
  2. Public Class FormContainer
  3.     Inherits Panel
  4.     Public WithEvents tmr As New Timer With {.Interval = 40, .Enabled = True}
  5.     Public avatar As Image
  6.     Property pLoc_x As Integer = 0
  7.     Sub New()
  8.         Me.DoubleBuffered = True
  9.     End Sub
  10.     Private Sub tmr_Tick(sender As Object, e As EventArgs) Handles tmr.Tick
  11.         If Not pLoc_x = -(1570) Then
  12.             pLoc_x -= 1
  13.         Else
  14.             pLoc_x = 0
  15.         End If
  16.        
  17.         Me.Refresh()
  18.     End Sub
  19. #Region "Round Rectangle"
  20.     Public Shared Function NTRound(rectangle As Rectangle, slope As Integer) As GraphicsPath
  21.         Dim path = New GraphicsPath(FillMode.Winding)
  22.         path.AddArc(rectangle.X - slope, rectangle.Y, slope, slope, 180.0F, 90.0F)
  23.         path.AddArc(rectangle.Right, rectangle.Y, slope, slope, 270.0F, 90.0F)
  24.         path.AddArc(rectangle.Right - slope, rectangle.Bottom - slope, slope, slope, 0.0F, 90.0F)
  25.         path.AddArc(rectangle.X, rectangle.Bottom - slope, slope, slope, 90.0F, 90.0F)
  26.         path.CloseFigure()
  27.         Return path
  28.     End Function
  29.  
  30.     Public Shared Function NTRound(x As Integer, y As Integer, height As Integer, width As Integer, slope As Integer) As GraphicsPath
  31.         Return Round(New Rectangle(x, y, height, width), slope)
  32.     End Function
  33.  
  34.     Public Shared Function Round(rectangle As Rectangle, slope As Integer) As GraphicsPath
  35.         Dim path = New GraphicsPath(FillMode.Winding)
  36.         path.AddArc(rectangle.X, rectangle.Y, slope, slope, 180.0F, 90.0F)
  37.         path.AddArc(rectangle.Right - slope, rectangle.Y, slope, slope, 270.0F, 90.0F)
  38.         path.AddArc(rectangle.Right - slope, rectangle.Bottom - slope, slope, slope, 0.0F, 90.0F)
  39.         path.AddArc(rectangle.X, rectangle.Bottom - slope, slope, slope, 90.0F, 90.0F)
  40.         path.CloseFigure()
  41.         Return path
  42.     End Function
  43.  
  44.     Public Shared Function Round(x As Integer, y As Integer, height As Integer, width As Integer, slope As Integer) As GraphicsPath
  45.         Return Round(New Rectangle(x, y, height, width), slope)
  46.     End Function
  47. #End Region
  48. #Region "ThemeDraggable"
  49.     Dim x, y As Integer
  50.     Private savePoint As New Point(0, 0)
  51.     Private isDragging As Boolean = False
  52.  
  53.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  54.         Dim dragRect As New Rectangle(0, 0, Me.Width, 30)
  55.         If dragRect.Contains(New Point(e.X, e.Y)) Then
  56.             Me.Cursor = Cursors.Hand
  57.             isDragging = True
  58.             savePoint = New Point(e.X, e.Y)
  59.  
  60.         End If
  61.  
  62.         MyBase.OnMouseDown(e)
  63.     End Sub
  64.  
  65.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  66.         isDragging = False
  67.         MyBase.OnMouseUp(e)
  68.     End Sub
  69.  
  70.     Private mouseX As Integer
  71.     Private mouseY As Integer
  72.     Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  73.  
  74.         mouseX = e.X
  75.         mouseY = e.Y
  76.         If isDragging Then
  77.             Dim screenPoint As Point = PointToScreen(e.Location)
  78.             Me.Cursor = Cursors.Hand
  79.             FindForm().Location = New Point(screenPoint.X - Me.savePoint.X, screenPoint.Y - Me.savePoint.Y)
  80.         End If
  81.         MyBase.OnMouseMove(e)
  82.         Invalidate()
  83.     End Sub
  84.  
  85. #End Region
  86.     Public Shared Function CropToCircle(srcImage As Image, backGround As Color) As Image
  87.         Dim dstImage As Image = New Bitmap(srcImage.Width, srcImage.Height, srcImage.PixelFormat)
  88.         Dim g As Graphics = Graphics.FromImage(dstImage)
  89.         Using br As Brush = New SolidBrush(backGround)
  90.             g.FillRectangle(br, 0, 0, dstImage.Width, dstImage.Height)
  91.         End Using
  92.         Dim path As New GraphicsPath()
  93.         path.AddEllipse(0, 0, dstImage.Width, dstImage.Height)
  94.         g.SetClip(path)
  95.         g.DrawImage(srcImage, 0, 0)
  96.  
  97.         Return dstImage
  98.     End Function
  99.     Public Function gb(e As Graphics, r As Rectangle, c1 As Color, c2 As Color) As LinearGradientBrush
  100.         Dim g As Graphics = e
  101.         Dim p1 As Point = r.Location
  102.         Dim p2 As Point = New Point(r.Right, r.Bottom)
  103.         Dim brsGradient As New System.Drawing.Drawing2D.LinearGradientBrush(p1, p2, c1, c2)
  104.         Return brsGradient
  105.     End Function
  106.     Function CheckStr(str As String, max As Integer) As String
  107.         Dim strmax As Integer
  108.         Try
  109.             strmax = str.Count
  110.         Catch ex As Exception
  111.             strmax = 1
  112.         End Try
  113.  
  114.         Dim newstr As String = ""
  115.         If strmax > max Then
  116.             Dim countt As Integer = 0
  117.             For Each Charr As Char In str
  118.                 countt += 1
  119.                 If countt <= max Then
  120.                     newstr += Charr
  121.                 ElseIf countt <= max + 3 Then
  122.                     newstr += "."
  123.                 End If
  124.             Next
  125.         Else
  126.             newstr = str
  127.         End If
  128.         Return newstr
  129.     End Function
  130.     Private Sub FormContainer_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
  131.         Dim g As Graphics = e.Graphics
  132.         g.DrawImage(My.Resources.bg, New Rectangle(0, 0, Me.Width, Me.Height))
  133.         g.DrawImage(My.Resources.Clouds, New Rectangle(pLoc_x, 0, 1920, 350))
  134.         g.DrawRectangle(New Pen(Color.FromArgb(133, 173, 245)), New Rectangle(0, 0, Me.Width - 1, Me.Height - 1))
  135.         g.DrawRectangle(New Pen(Color.FromArgb(106, 146, 242)), New Rectangle(1, 1, Me.Width - 3, Me.Height - 3))
  136.  
  137.         g.SmoothingMode = SmoothingMode.HighQuality
  138.  
  139.     End Sub
  140. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement