Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #region Import
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- #endregion
- public class Ce_SocialButton : Control
- {
- #region Variables
- private Image _Image;
- private Size _ImageSize;
- private Color EllipseColor; // VBConversions Note: Initial value cannot be assigned here since it is non-static. Assignment has been moved to the class constructors.
- #endregion
- #region Properties
- public Image Image
- {
- get
- {
- return _Image;
- }
- set
- {
- if (value == null)
- {
- _ImageSize = Size.Empty;
- }
- else
- {
- _ImageSize = value.Size;
- }
- _Image = value;
- Invalidate();
- }
- }
- protected Size ImageSize
- {
- get
- {
- return _ImageSize;
- }
- }
- #endregion
- #region EventArgs
- protected override void OnResize(EventArgs e)
- {
- base.OnResize(e);
- this.Size = new Size(54, 54);
- }
- protected override void OnMouseEnter(EventArgs e)
- {
- base.OnMouseEnter(e);
- EllipseColor = Color.FromArgb(181, 41, 42);
- Refresh();
- }
- protected override void OnMouseLeave(EventArgs e)
- {
- base.OnMouseLeave(e);
- EllipseColor = Color.FromArgb(66, 76, 85);
- Refresh();
- }
- protected override void OnMouseDown(MouseEventArgs e)
- {
- base.OnMouseDown(e);
- EllipseColor = Color.FromArgb(153, 34, 34);
- Focus();
- Refresh();
- }
- protected override void OnMouseUp(MouseEventArgs e)
- {
- base.OnMouseUp(e);
- EllipseColor = Color.FromArgb(181, 41, 42);
- Refresh();
- }
- #endregion
- #region Image Designer
- private static PointF ImageLocation(StringFormat SF, SizeF Area, SizeF ImageArea)
- {
- PointF MyPoint = new PointF();
- switch (SF.Alignment)
- {
- case StringAlignment.Center:
- MyPoint.X = (float)((Area.Width - ImageArea.Width) / 2);
- break;
- }
- switch (SF.LineAlignment)
- {
- case StringAlignment.Center:
- MyPoint.Y = (float)((Area.Height - ImageArea.Height) / 2);
- break;
- }
- return MyPoint;
- }
- private StringFormat GetStringFormat(ContentAlignment _ContentAlignment)
- {
- StringFormat SF = new StringFormat();
- switch (_ContentAlignment)
- {
- case ContentAlignment.MiddleCenter:
- SF.LineAlignment = StringAlignment.Center;
- SF.Alignment = StringAlignment.Center;
- break;
- }
- return SF;
- }
- #endregion
- public Ce_SocialButton()
- {
- DoubleBuffered = true;
- EllipseColor = Color.FromArgb(66, 76, 85);
- }
- protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
- {
- Graphics G = e.Graphics;
- G.Clear(Parent.BackColor);
- G.SmoothingMode = SmoothingMode.HighQuality;
- PointF ImgPoint = ImageLocation(GetStringFormat(ContentAlignment.MiddleCenter), Size, ImageSize);
- G.FillEllipse(new SolidBrush(EllipseColor), new Rectangle(0, 0, 53, 53));
- // HINTS:
- // The best size for the drawn image is 32x32\
- // The best matching color of drawn image is (RGB: 31, 40, 49)
- if (Image != null)
- {
- G.DrawImage(_Image, (int)ImgPoint.X, (int)ImgPoint.Y, ImageSize.Width, ImageSize.Height);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement