Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '' <summary>
- '' iPalette
- '' Color Palette Creater
- '' Author : THE LORD
- '' Release Date : Friday, December 30, 2016
- '' </summary>
- #Region " Control "
- Public Class iPalette : Inherits Control
- #Region " Variables "
- Private R1, R2, R3, R4, R5 As Rectangle, IMG As Bitmap
- Private _Color1 As Color = ColorTranslator.FromHtml("#E2C2C6")
- Private _Color2 As Color = ColorTranslator.FromHtml("#BA93A4")
- Private _Color3 As Color = ColorTranslator.FromHtml("#935B86")
- Private _Color4 As Color = ColorTranslator.FromHtml("#6B346B")
- Private _Color5 As Color = ColorTranslator.FromHtml("#3D1A4C")
- Private _RectWidths As Integer = 50
- Private _Savable As Boolean = False
- Private _ShowHTMLColor, _ShowRGBColor As Boolean
- #End Region
- #Region " Properties "
- Public Property Color1 As Color
- Get
- Return _Color1
- End Get
- Set(value As Color)
- _Color1 = value
- Invalidate()
- End Set
- End Property
- Public Property Color2 As Color
- Get
- Return _Color2
- End Get
- Set(value As Color)
- _Color2 = value
- Invalidate()
- End Set
- End Property
- Public Property Color3 As Color
- Get
- Return _Color3
- End Get
- Set(value As Color)
- _Color3 = value
- Invalidate()
- End Set
- End Property
- Public Property Color4 As Color
- Get
- Return _Color4
- End Get
- Set(value As Color)
- _Color4 = value
- Invalidate()
- End Set
- End Property
- Public Property Color5 As Color
- Get
- Return _Color5
- End Get
- Set(value As Color)
- _Color5 = value
- Invalidate()
- End Set
- End Property
- Public Property RectWidths As Integer
- Get
- Return _RectWidths
- End Get
- Set(value As Integer)
- _RectWidths = value
- Invalidate()
- End Set
- End Property
- Public Property Savable As Boolean
- Get
- Return _Savable
- End Get
- Set(value As Boolean)
- _Savable = value
- Invalidate()
- End Set
- End Property
- Public Property ShowHTMLColor As Boolean
- Get
- Return _ShowHTMLColor
- End Get
- Set(value As Boolean)
- _ShowHTMLColor = value
- Invalidate()
- End Set
- End Property
- Public Property ShowRGBColor As Boolean
- Get
- Return _ShowRGBColor
- End Get
- Set(value As Boolean)
- _ShowRGBColor = value
- Invalidate()
- End Set
- End Property
- #End Region
- #Region " Events "
- Protected Overrides Sub OnClick(e As EventArgs)
- If Savable Then
- Using SFD As New SaveFileDialog With {.Filter = "Jpeg File(*.jpg)|*.jpg"}
- If SFD.ShowDialog = DialogResult.OK Then
- IMG.Save(SFD.FileName, System.Drawing.Imaging.ImageFormat.Jpeg)
- End If
- End Using
- End If
- MyBase.OnClick(e)
- End Sub
- #End Region
- #Region " Constructors "
- Sub New()
- SetStyle(ControlStyles.OptimizedDoubleBuffer Or ControlStyles.AllPaintingInWmPaint Or _
- ControlStyles.ResizeRedraw Or ControlStyles.UserPaint Or _
- ControlStyles.SupportsTransparentBackColor, True)
- DoubleBuffered = True
- UpdateStyles()
- BackColor = Color.Transparent
- Font = New Font("Arial", 6)
- ShowHTMLColor = True
- ShowRGBColor = True
- End Sub
- #End Region
- #Region " Draw Control "
- Protected Overrides Sub OnPaint(e As PaintEventArgs)
- Width = RectWidths * 5
- R1 = New Rectangle(0, 0, RectWidths, Height)
- R2 = New Rectangle(RectWidths, 0, RectWidths, Height)
- R3 = New Rectangle(RectWidths * 2, 0, RectWidths, Height)
- R4 = New Rectangle(RectWidths * 3, 0, RectWidths, Height)
- R5 = New Rectangle(RectWidths * 4, 0, RectWidths, Height)
- Using B As New Bitmap(Width, Height), G As Graphics = Graphics.FromImage(B)
- With G
- .TextRenderingHint = Drawing.Text.TextRenderingHint.AntiAlias
- .FillRectangle(New SolidBrush(Color1), R1)
- .FillRectangle(New SolidBrush(Color2), R2)
- .FillRectangle(New SolidBrush(Color3), R3)
- .FillRectangle(New SolidBrush(Color4), R4)
- .FillRectangle(New SolidBrush(Color5), R5)
- If ShowHTMLColor Then
- .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})
- .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})
- .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})
- .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})
- .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})
- End If
- If ShowRGBColor Then
- .DrawString(GetRGBFromColor(Color1), Font, New SolidBrush(Color2), New Rectangle(R1.X, R1.Height - 20, R1.Width, R1.Height), New StringFormat With {.Alignment = StringAlignment.Center})
- .DrawString(GetRGBFromColor(Color2), Font, New SolidBrush(Color3), New Rectangle(R2.X, R2.Height - 20, R2.Width, R2.Height), New StringFormat With {.Alignment = StringAlignment.Center})
- .DrawString(GetRGBFromColor(Color3), Font, New SolidBrush(Color4), New Rectangle(R3.X, R3.Height - 20, R3.Width, R3.Height), New StringFormat With {.Alignment = StringAlignment.Center})
- .DrawString(GetRGBFromColor(Color4), Font, New SolidBrush(Color5), New Rectangle(R4.X, R4.Height - 20, R4.Width, R4.Height), New StringFormat With {.Alignment = StringAlignment.Center})
- .DrawString(GetRGBFromColor(Color5), Font, New SolidBrush(Color4), New Rectangle(R5.X, R5.Height - 20, R5.Width, R5.Height), New StringFormat With {.Alignment = StringAlignment.Center})
- End If
- End With
- e.Graphics.DrawImage(B, 0, 0)
- G.Dispose()
- IMG = New Bitmap(B)
- B.Dispose()
- End Using
- End Sub
- #End Region
- #Region " Helper Methods "
- Public Function GetRGBFromColor(ByVal C As Color) As String
- Return String.Format("({0},{1},{2})", C.R, C.G, C.B)
- End Function
- #End Region
- End Class
- #End Region
Add Comment
Please, Sign In to add comment