Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// <summary>
- /// CePalette
- /// Color Palette Creater
- /// Author : Yassine Abbani
- /// </summary>
- #region NameSpaces
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- #endregion
- #region Control
- public class Ce_Palette : Control
- {
- #region Variables
- private Rectangle R1, R2, R3, R4, R5;
- private Bitmap IMG;
- private Color _Color1 = ColorTranslator.FromHtml("#E2C2C6");
- private Color _Color2 = ColorTranslator.FromHtml("#BA93A4");
- private Color _Color3 = ColorTranslator.FromHtml("#935B86");
- private Color _Color4 = ColorTranslator.FromHtml("#6B346B");
- private Color _Color5 = ColorTranslator.FromHtml("#3D1A4C");
- private int _RectWidths = 50;
- private bool _Savable = false;
- private bool _ShowHTMLColor, _ShowRGBColor;
- #endregion
- #region Constructors
- public Ce_Palette()
- {
- SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint |
- ControlStyles.ResizeRedraw | ControlStyles.UserPaint |
- ControlStyles.SupportsTransparentBackColor, true);
- DoubleBuffered = true;
- UpdateStyles();
- BackColor = Color.Transparent;
- Font = new Font("Arial", 6);
- ShowHTMLColor = true;
- ShowRGBColor = true;
- }
- #endregion
- #region Properties
- public Color ColorA
- {
- get
- {
- return _Color1;
- }
- set
- {
- _Color1 = value;
- Invalidate();
- }
- }
- public Color ColorB
- {
- get
- {
- return _Color2;
- }
- set
- {
- _Color2 = value;
- Invalidate();
- }
- }
- public Color ColorC
- {
- get
- {
- return _Color3;
- }
- set
- {
- _Color3 = value;
- Invalidate();
- }
- }
- public Color ColorD
- {
- get
- {
- return _Color4;
- }
- set
- {
- _Color4 = value;
- Invalidate();
- }
- }
- public Color ColorE
- {
- get
- {
- return _Color5;
- }
- set
- {
- _Color5 = value;
- Invalidate();
- }
- }
- public int RectWidths
- {
- get
- {
- return _RectWidths;
- }
- set
- {
- _RectWidths = value;
- Invalidate();
- }
- }
- public bool ShowHTMLColor
- {
- get
- {
- return _ShowHTMLColor;
- }
- set
- {
- _ShowHTMLColor = value;
- Invalidate();
- }
- }
- public bool ShowRGBColor
- {
- get
- {
- return _ShowRGBColor;
- }
- set
- {
- _ShowRGBColor = value;
- Invalidate();
- }
- }
- public bool Savable
- {
- get
- {
- return _Savable;
- }
- set
- {
- _Savable = value;
- Invalidate();
- }
- }
- #endregion
- #region Events
- protected override void OnClick(EventArgs e)
- {
- if (Savable)
- {
- using (SaveFileDialog sfd = new SaveFileDialog() { Filter = "Jpeg File(*.jpg)|*.jpg" })
- {
- if (sfd.ShowDialog() == DialogResult.OK)
- {
- IMG.Save(sfd.FileName, System.Drawing.Imaging.ImageFormat.Jpeg);
- }
- }
- }
- base.OnClick(e);
- }
- #endregion
- #region Draw Control
- protected override void OnPaint(PaintEventArgs e)
- {
- 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 (Bitmap B = new Bitmap(Width, Height))
- using (Graphics G = Graphics.FromImage(B))
- {
- G.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
- G.FillRectangle(new SolidBrush(ColorA), R1);
- G.FillRectangle(new SolidBrush(ColorB), R2);
- G.FillRectangle(new SolidBrush(ColorC), R3);
- G.FillRectangle(new SolidBrush(ColorD), R4);
- G.FillRectangle(new SolidBrush(ColorE), R5);
- if (ShowHTMLColor)
- {
- G.DrawString(ColorTranslator.ToHtml(ColorA), Font, new SolidBrush(ColorB), new Rectangle(R1.X, R1.Height - 30, R1.Width, R1.Height), new StringFormat { Alignment = StringAlignment.Center });
- G.DrawString(ColorTranslator.ToHtml(ColorB), Font, new SolidBrush(ColorC), new Rectangle(R2.X, R2.Height - 30, R2.Width, R2.Height), new StringFormat { Alignment = StringAlignment.Center });
- G.DrawString(ColorTranslator.ToHtml(ColorC), Font, new SolidBrush(ColorD), new Rectangle(R3.X, R3.Height - 30, R3.Width, R3.Height), new StringFormat { Alignment = StringAlignment.Center });
- G.DrawString(ColorTranslator.ToHtml(ColorD), Font, new SolidBrush(ColorE), new Rectangle(R4.X, R4.Height - 30, R4.Width, R4.Height), new StringFormat { Alignment = StringAlignment.Center });
- G.DrawString(ColorTranslator.ToHtml(ColorE), Font, new SolidBrush(ColorD), new Rectangle(R5.X, R5.Height - 30, R5.Width, R5.Height), new StringFormat { Alignment = StringAlignment.Center });
- }
- if (ShowRGBColor)
- {
- G.DrawString(GetRGBFromColor(ColorA), Font, new SolidBrush(ColorB), new Rectangle(R1.X, R1.Height - 20, R1.Width, R1.Height), new StringFormat { Alignment = StringAlignment.Center });
- G.DrawString(GetRGBFromColor(ColorB), Font, new SolidBrush(ColorC), new Rectangle(R2.X, R2.Height - 20, R2.Width, R2.Height), new StringFormat { Alignment = StringAlignment.Center });
- G.DrawString(GetRGBFromColor(ColorC), Font, new SolidBrush(ColorD), new Rectangle(R3.X, R3.Height - 20, R3.Width, R3.Height), new StringFormat { Alignment = StringAlignment.Center });
- G.DrawString(GetRGBFromColor(ColorD), Font, new SolidBrush(ColorE), new Rectangle(R4.X, R4.Height - 20, R4.Width, R4.Height), new StringFormat { Alignment = StringAlignment.Center });
- G.DrawString(GetRGBFromColor(ColorE), Font, new SolidBrush(ColorD), new Rectangle(R5.X, R5.Height - 20, R5.Width, R5.Height), new StringFormat { Alignment = StringAlignment.Center });
- }
- e.Graphics.DrawImage(B, 0, 0);
- G.Dispose();
- IMG = new Bitmap(B);
- B.Dispose();
- }
- }
- #endregion
- #region Helper MEthods
- public string GetRGBFromColor(Color C)
- {
- return String.Format("({0},{1},{2})", C.R, C.G, C.B);
- }
- #endregion
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement