THE_LORD

iPalette ~ GDI Color Palette Creater

Dec 30th, 2016
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 7.19 KB | None | 0 0
  1.  
  2. '' <summary>
  3. '' iPalette
  4. '' Color Palette Creater
  5. '' Author : THE LORD
  6. '' Release Date : Friday, December 30, 2016
  7. '' </summary>
  8.  
  9. #Region " Control "
  10.  
  11. Public Class iPalette : Inherits Control
  12.  
  13. #Region " Variables "
  14.  
  15.     Private R1, R2, R3, R4, R5 As Rectangle, IMG As Bitmap
  16.     Private _Color1 As Color = ColorTranslator.FromHtml("#E2C2C6")
  17.     Private _Color2 As Color = ColorTranslator.FromHtml("#BA93A4")
  18.     Private _Color3 As Color = ColorTranslator.FromHtml("#935B86")
  19.     Private _Color4 As Color = ColorTranslator.FromHtml("#6B346B")
  20.     Private _Color5 As Color = ColorTranslator.FromHtml("#3D1A4C")
  21.     Private _RectWidths As Integer = 50
  22.     Private _Savable As Boolean = False
  23.     Private _ShowHTMLColor, _ShowRGBColor As Boolean
  24.  
  25. #End Region
  26.  
  27. #Region " Properties "
  28.  
  29.     Public Property Color1 As Color
  30.         Get
  31.             Return _Color1
  32.         End Get
  33.         Set(value As Color)
  34.             _Color1 = value
  35.             Invalidate()
  36.         End Set
  37.     End Property
  38.  
  39.     Public Property Color2 As Color
  40.         Get
  41.             Return _Color2
  42.         End Get
  43.         Set(value As Color)
  44.             _Color2 = value
  45.             Invalidate()
  46.         End Set
  47.     End Property
  48.  
  49.     Public Property Color3 As Color
  50.         Get
  51.             Return _Color3
  52.         End Get
  53.         Set(value As Color)
  54.             _Color3 = value
  55.             Invalidate()
  56.         End Set
  57.     End Property
  58.  
  59.     Public Property Color4 As Color
  60.         Get
  61.             Return _Color4
  62.         End Get
  63.         Set(value As Color)
  64.             _Color4 = value
  65.             Invalidate()
  66.         End Set
  67.     End Property
  68.  
  69.     Public Property Color5 As Color
  70.         Get
  71.             Return _Color5
  72.         End Get
  73.         Set(value As Color)
  74.             _Color5 = value
  75.             Invalidate()
  76.         End Set
  77.     End Property
  78.  
  79.     Public Property RectWidths As Integer
  80.         Get
  81.             Return _RectWidths
  82.         End Get
  83.         Set(value As Integer)
  84.             _RectWidths = value
  85.             Invalidate()
  86.         End Set
  87.     End Property
  88.  
  89.     Public Property Savable As Boolean
  90.         Get
  91.             Return _Savable
  92.         End Get
  93.         Set(value As Boolean)
  94.             _Savable = value
  95.             Invalidate()
  96.         End Set
  97.     End Property
  98.  
  99.     Public Property ShowHTMLColor As Boolean
  100.         Get
  101.             Return _ShowHTMLColor
  102.         End Get
  103.         Set(value As Boolean)
  104.             _ShowHTMLColor = value
  105.             Invalidate()
  106.         End Set
  107.     End Property
  108.  
  109.     Public Property ShowRGBColor As Boolean
  110.         Get
  111.             Return _ShowRGBColor
  112.         End Get
  113.         Set(value As Boolean)
  114.             _ShowRGBColor = value
  115.             Invalidate()
  116.         End Set
  117.     End Property
  118.  
  119. #End Region
  120.  
  121. #Region " Events "
  122.  
  123.     Protected Overrides Sub OnClick(e As EventArgs)
  124.         If Savable Then
  125.             Using SFD As New SaveFileDialog With {.Filter = "Jpeg File(*.jpg)|*.jpg"}
  126.                 If SFD.ShowDialog = DialogResult.OK Then
  127.                     IMG.Save(SFD.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)
  128.                 End If
  129.             End Using
  130.         End If
  131.         MyBase.OnClick(e)
  132.     End Sub
  133.  
  134. #End Region
  135.  
  136. #Region " Constructors "
  137.  
  138.     Sub New()
  139.         SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.AllPaintingInWmPaint Or _
  140.                ControlStyles.ResizeRedraw Or ControlStyles.UserPaint Or _
  141.                ControlStyles.SupportsTransparentBackColor, True)
  142.         DoubleBuffered = True
  143.         UpdateStyles()
  144.         BackColor = Color.Transparent
  145.         Font = New Font("Arial", 6)
  146.         ShowHTMLColor = True
  147.         ShowRGBColor = True
  148.     End Sub
  149.  
  150. #End Region
  151.  
  152. #Region " Draw Control "
  153.  
  154.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  155.         Width = RectWidths * 5
  156.         R1 = New Rectangle(0, 0, RectWidths, Height)
  157.         R2 = New Rectangle(RectWidths, 0, RectWidths, Height)
  158.         R3 = New Rectangle(RectWidths * 2, 0, RectWidths, Height)
  159.         R4 = New Rectangle(RectWidths * 3, 0, RectWidths, Height)
  160.         R5 = New Rectangle(RectWidths * 4, 0, RectWidths, Height)
  161.         Using B As New Bitmap(Width, Height), G As Graphics = Graphics.FromImage(B)
  162.             With G
  163.  
  164.                 .TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
  165.  
  166.                 .FillRectangle(New SolidBrush(Color1), R1)
  167.                 .FillRectangle(New SolidBrush(Color2), R2)
  168.                 .FillRectangle(New SolidBrush(Color3), R3)
  169.                 .FillRectangle(New SolidBrush(Color4), R4)
  170.                 .FillRectangle(New SolidBrush(Color5), R5)
  171.  
  172.                 If ShowHTMLColor Then
  173.                     .DrawString(ColorTranslator.ToHtml(Color1), Font, New SolidBrush(Color2), New Rectangle(R1.X, R1.Height - 30, R1.Width, R1.Height), New StringFormat With {.Alignment = StringAlignment.Center})
  174.                     .DrawString(ColorTranslator.ToHtml(Color2), Font, New SolidBrush(Color3), New Rectangle(R2.X, R2.Height - 30, R2.Width, R2.Height), New StringFormat With {.Alignment = StringAlignment.Center})
  175.                     .DrawString(ColorTranslator.ToHtml(Color3), Font, New SolidBrush(Color4), New Rectangle(R3.X, R3.Height - 30, R3.Width, R3.Height), New StringFormat With {.Alignment = StringAlignment.Center})
  176.                     .DrawString(ColorTranslator.ToHtml(Color4), Font, New SolidBrush(Color5), New Rectangle(R4.X, R4.Height - 30, R4.Width, R4.Height), New StringFormat With {.Alignment = StringAlignment.Center})
  177.                     .DrawString(ColorTranslator.ToHtml(Color5), Font, New SolidBrush(Color4), New Rectangle(R5.X, R5.Height - 30, R5.Width, R5.Height), New StringFormat With {.Alignment = StringAlignment.Center})
  178.                 End If
  179.                 If ShowRGBColor Then
  180.                     .DrawString(GetRGBFromColor(Color1), Font, New SolidBrush(Color2), New Rectangle(R1.X, R1.Height - 20, R1.Width, R1.Height), New StringFormat With {.Alignment = StringAlignment.Center})
  181.                     .DrawString(GetRGBFromColor(Color2), Font, New SolidBrush(Color3), New Rectangle(R2.X, R2.Height - 20, R2.Width, R2.Height), New StringFormat With {.Alignment = StringAlignment.Center})
  182.                     .DrawString(GetRGBFromColor(Color3), Font, New SolidBrush(Color4), New Rectangle(R3.X, R3.Height - 20, R3.Width, R3.Height), New StringFormat With {.Alignment = StringAlignment.Center})
  183.                     .DrawString(GetRGBFromColor(Color4), Font, New SolidBrush(Color5), New Rectangle(R4.X, R4.Height - 20, R4.Width, R4.Height), New StringFormat With {.Alignment = StringAlignment.Center})
  184.                     .DrawString(GetRGBFromColor(Color5), Font, New SolidBrush(Color4), New Rectangle(R5.X, R5.Height - 20, R5.Width, R5.Height), New StringFormat With {.Alignment = StringAlignment.Center})
  185.                 End If
  186.             End With
  187.             e.Graphics.DrawImage(B, 0, 0)
  188.             G.Dispose()
  189.             IMG = New Bitmap(B)
  190.             B.Dispose()
  191.         End Using
  192.     End Sub
  193.  
  194. #End Region
  195.  
  196. #Region " Helper Methods "
  197.  
  198.     Public Function GetRGBFromColor(ByVal C As Color) As String
  199.         Return String.Format("({0},{1},{2})", C.R, C.G, C.B)
  200.     End Function
  201.  
  202. #End Region
  203.  
  204. End Class
  205.  
  206. #End Region
Add Comment
Please, Sign In to add comment