Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Directives
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Drawing.Text;
- using System.Linq;
- using System.Runtime.InteropServices;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- #endregion
- #region Browse
- /* Copyright & Contact
- * --------------------------------------------------------------------------------<
- * Tool Name : Card *
- * From Project : Creator Eye *
- * Project Lang : C# *
- * Creator : Yassine Abbani *
- * Facebook : https://www.facebook.com/YassineAbbani.user *
- * Pastebin : https://pastebin.com/u/Yassine_Abbani *
- * Youtube : https://www.youtube.com/channel/UCqvOCRs3HWbPH4yuZuTx8mw *
- * Version : 1.0 Beta *
- * Color : Dark Theme *
- * Style : Smal *
- *>--------------------------------------------------------------------------------<
- */
- /* Features
- * ------------------------
- * We Was Converting rbg color to Html color
- * Creators Eye Cards is a custom control that arranges your info or controls inside a beautiful panel. It makes your dashboard presentation more organized and aligned.
- */
- /* history
- * ------------------------
- * 1.0 (24 Feb 2018):
- *
- * Custom Properties
- * Ability to add image to the left side of the card using property
- * Ability to change the color of the card image using Color property
- */
- #endregion
- #region Card
- public class Ce_Card : Control
- {
- #region Variables
- FontManager font = new FontManager();
- Image image;
- string information = "Type here any thing you want to type :) ";
- string Titelcolor = "#00AEDB";
- string thumbnailcolor = "#00AEDB";
- Color BgColor;
- Color StringColor;
- Color ThumbnailBGColor;
- Color BorderColor = ColorTranslator.FromHtml("#00AEDB");
- #endregion
- #region Properties
- [Category("Appearance")]
- public Image Image
- {
- get
- {
- return image;
- }
- set
- {
- image = value;
- Invalidate();
- }
- }
- [Category("Appearance")]
- public string ThumbnailColor
- {
- get { return thumbnailcolor; }
- set
- {
- thumbnailcolor = value;
- Invalidate();
- }
- }
- [Category("Appearance")]
- public string TitelColor
- {
- get { return Titelcolor; }
- set
- {
- Titelcolor = value;
- Invalidate();
- }
- }
- [Category("Appearance")]
- public string Description
- {
- get { return information; }
- set
- {
- information = value;
- Invalidate();
- }
- }
- [Browsable(false)]
- public Font Font
- {
- get { return base.Font; }
- set { base.Font = value; }
- }
- [Browsable(false)]
- public Color ForeColor
- {
- get { return base.ForeColor; }
- set { base.ForeColor = value; }
- }
- #endregion
- #region Events
- protected override void OnMouseEnter(EventArgs e)
- {
- base.OnMouseEnter(e);
- BgColor = ColorTranslator.FromHtml("#111111");
- Refresh();
- }
- protected override void OnMouseLeave(EventArgs e)
- {
- base.OnMouseLeave(e);
- BgColor = ColorTranslator.FromHtml("#262626");
- Refresh();
- }
- protected override void OnTextChanged(EventArgs e)
- {
- base.OnTextChanged(e);
- Invalidate();
- }
- protected override void OnResize(EventArgs e)
- {
- base.OnResize(e);
- Height = 52;
- }
- #endregion
- #region Constructors
- public Ce_Card()
- {
- Height = 52; Width = 182; DoubleBuffered = true;
- }
- #endregion
- #region Draw Control
- static class DrawHelper
- {
- public static GraphicsPath CreateRoundRect(float x, float y, float width, float height, float radius)
- {
- GraphicsPath gp = new GraphicsPath();
- gp.AddLine(x + radius, y, x + width - (radius * 2), y);
- gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90);
- gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2));
- gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, radius * 2, 0, 90);
- gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height);
- gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90);
- gp.AddLine(x, y + height - (radius * 2), x, y + radius);
- gp.AddArc(x, y, radius * 2, radius * 2, 180, 90);
- gp.CloseFigure();
- return gp;
- }
- public static GraphicsPath CreateUpRoundRect(float x, float y, float width, float height, float radius)
- {
- GraphicsPath gp = new GraphicsPath();
- gp.AddLine(x + radius, y, x + width - (radius * 2), y);
- gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90);
- gp.AddLine(x + width, y + radius, x + width, y + height - (radius * 2) + 1);
- gp.AddArc(x + width - (radius * 2), y + height - (radius * 2), radius * 2, 2, 0, 90);
- gp.AddLine(x + width, y + height, x + radius, y + height);
- gp.AddArc(x, y + height - (radius * 2) + 1, radius * 2, 1, 90, 90);
- gp.AddLine(x, y + height, x, y + radius);
- gp.AddArc(x, y, radius * 2, radius * 2, 180, 90);
- gp.CloseFigure();
- return gp;
- }
- public static GraphicsPath CreateLeftRoundRect(float x, float y, float width, float height, float radius)
- {
- GraphicsPath gp = new GraphicsPath();
- gp.AddLine(x + radius, y, x + width - (radius * 2), y);
- gp.AddArc(x + width - (radius * 2), y, radius * 2, radius * 2, 270, 90);
- gp.AddLine(x + width, y + 0, x + width, y + height);
- gp.AddArc(x + width - (radius * 2), y + height - (1), radius * 2, 1, 0, 90);
- gp.AddLine(x + width - (radius * 2), y + height, x + radius, y + height);
- gp.AddArc(x, y + height - (radius * 2), radius * 2, radius * 2, 90, 90);
- gp.AddLine(x, y + height - (radius * 2), x, y + radius);
- gp.AddArc(x, y, radius * 2, radius * 2, 180, 90);
- gp.CloseFigure();
- return gp;
- }
- public static Color BlendColor(Color backgroundColor, Color frontColor)
- {
- double ratio = 0 / 255d;
- double invRatio = 1d - ratio;
- int r = (int)((backgroundColor.R * invRatio) + (frontColor.R * ratio));
- int g = (int)((backgroundColor.G * invRatio) + (frontColor.G * ratio));
- int b = (int)((backgroundColor.B * invRatio) + (frontColor.B * ratio));
- return Color.FromArgb(r, g, b);
- }
- }
- public class FontManager
- {
- public Font MyFont_Medium15;
- public Font MyFont_Medium10;
- public Font MyFont_Regular10;
- public Font MyFont_Medium9;
- public Font MyFont_Regular9;
- public FontManager()
- {
- MyFont_Medium15 = new Font("Century Gothic", 15f);
- MyFont_Medium10 = new Font("Century Gothic", 10f);
- MyFont_Regular10 = new Font("Century Gothic", 10f);
- MyFont_Medium9 = new Font("Century Gothic", 9f);
- MyFont_Regular9 = new Font("Century Gothic", 9f);
- }
- private PrivateFontCollection privateFontCollection = new PrivateFontCollection();
- [DllImport("gdi32.dll")]
- private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pvd, [In] ref uint pcFonts);
- private FontFamily LoadFont(byte[] fontResource)
- {
- int dataLength = fontResource.Length;
- IntPtr fontPtr = Marshal.AllocCoTaskMem(dataLength);
- Marshal.Copy(fontResource, 0, fontPtr, dataLength);
- uint cFonts = 0;
- AddFontMemResourceEx(fontPtr, (uint)fontResource.Length, IntPtr.Zero, ref cFonts);
- privateFontCollection.AddMemoryFont(fontPtr, dataLength);
- return privateFontCollection.Families.Last();
- }
- }
- protected override void OnPaint(PaintEventArgs e)
- {
- base.OnPaint(e);
- Graphics G = e.Graphics;
- G.SmoothingMode = SmoothingMode.HighQuality;
- G.Clear(Parent.BackColor);
- StringColor = ColorTranslator.FromHtml(Titelcolor);
- ThumbnailBGColor = ColorTranslator.FromHtml(thumbnailcolor);
- var BG = DrawHelper.CreateRoundRect(1, 1, Width - 3, Height - 3, 1);
- var ThumbnailBG = DrawHelper.CreateLeftRoundRect(1, 1, 50, 49, 1);
- G.FillPath(new SolidBrush(BgColor), BG);
- G.DrawPath(new Pen(BorderColor), BG);
- G.FillPath(new SolidBrush(ThumbnailBGColor), ThumbnailBG);
- G.DrawPath(new Pen(ThumbnailBGColor), ThumbnailBG);
- if (image != null)
- { G.DrawImage(image, 3, 3, 48, 47); }
- if (Enabled)
- { G.DrawString(Text, font.MyFont_Medium10, new SolidBrush(StringColor), new PointF(58.6f, 9f)); }
- else
- { G.DrawString("Wait...", font.MyFont_Medium10, new SolidBrush(StringColor), new PointF(58.6f, 9f)); }
- G.TextRenderingHint = TextRenderingHint.AntiAlias;
- G.DrawString(information, font.MyFont_Regular9, new SolidBrush(ColorTranslator.FromHtml("#757B7A")), new PointF(59.1f, 26f));
- }
- #endregion
- }
- #endregion
- #region Pens
- public sealed class Pens
- {
- public static Pen Red
- {
- get { return new Pen(Colors.Red); }
- }
- public static Pen LightRed
- {
- get { return new Pen(Colors.LightRed); }
- }
- public static Pen DarkRed
- {
- get { return new Pen(Colors.DarkRed); }
- }
- public static Pen Blue
- {
- get { return new Pen(Colors.Blue); }
- }
- public static Pen LighterBlue
- {
- get { return new Pen(Colors.LighterBlue); }
- }
- public static Pen DarkBlue
- {
- get { return new Pen(Colors.DarkBlue); }
- }
- public static Pen White
- {
- get { return new Pen(Colors.White); }
- }
- public static Pen Silver
- {
- get { return new Pen(Colors.Silver); }
- }
- public static Pen LightSilver
- {
- get { return new Pen(Colors.Gray); }
- }
- public static Pen LighterSilver
- {
- get { return new Pen(Colors.LighterSilver); }
- }
- public static Pen DarkGray
- {
- get { return new Pen(Colors.DarkGray); }
- }
- public static Pen Gray
- {
- get { return new Pen(Colors.Gray); }
- }
- public static Pen LightGray
- {
- get { return new Pen(Colors.LightGray); }
- }
- public static Pen LighterGray
- {
- get { return new Pen(Colors.LighterGray); }
- }
- }
- #endregion
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement