Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.ComponentModel.Design;
- using System.Drawing;
- using System.Drawing.Text;
- using System.Windows.Forms;
- [System.ComponentModel.Designer(typeof(NButtonDesigner))]
- internal class NButton : Control
- {
- private Color _ForeColor = Color.White;
- private Color _BaseColor = Color.Crimson;
- private Color _BorderColor = Color.Black;
- public string _ButtonText = "Button";
- public NButton()
- {
- SetStyle(ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer | ControlStyles.SupportsTransparentBackColor, true);
- DoubleBuffered = true;
- UpdateStyles();
- BackColor = Color.Transparent;
- Font = new Font("Segoe UI Light", 10);
- }
- public new Color ForeColor
- {
- get { return _ForeColor; }
- set { _ForeColor = value; Invalidate(); }
- }
- public Color BaseColor
- {
- get { return _BaseColor; }
- set { _BaseColor = value; Invalidate(); }
- }
- public Color BorderColor
- {
- get { return _BorderColor; }
- set { _BorderColor = value; Invalidate(); }
- }
- protected override void OnPaint(PaintEventArgs pevent)
- {
- Graphics g = pevent.Graphics;
- g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
- Rectangle r = new Rectangle(0, 0, Width - 1, Height - 1);
- using (SolidBrush BG = new SolidBrush(BaseColor))
- {
- using (SolidBrush F = new SolidBrush(ForeColor))
- {
- using (Pen BD = new Pen(BorderColor))
- {
- using (StringFormat SF = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center })
- {
- g.FillRectangle(BG, r);
- g.DrawRectangle(BD, r);
- g.DrawString(Text, Font, F, r, SF);
- }
- }
- }
- }
- }
- }
- internal class NButtonDesigner : System.Windows.Forms.Design.ControlDesigner
- {
- private readonly string[] _PropertiesToStay = { "ForeColor", "BaseColor", "Size", "Location","BorderColor","Font", "Text", "Name","TabIndex" };
- protected override void PostFilterProperties(IDictionary properties)
- {
- List<string> _ListToRemove = new List<string>();
- foreach (var item in properties.Keys)
- {
- if (!((IList) _PropertiesToStay).Contains(item))
- {
- _ListToRemove.Add(item.ToString());
- }
- }
- foreach (var property in _ListToRemove)
- {
- properties.Remove(property);
- }
- base.PostFilterProperties(properties);
- }
- private DesignerActionListCollection actionListCollection;
- public override DesignerActionListCollection ActionLists
- {
- get
- {
- if (actionListCollection == null)
- {
- actionListCollection = new DesignerActionListCollection();
- actionListCollection.Add(new NButtonActionList(Component));
- }
- return actionListCollection;
- }
- }
- }
- internal class NButtonActionList : DesignerActionList
- {
- private readonly NButton _NButton;
- public NButtonActionList(IComponent component) : base(component)
- {
- _NButton = (NButton) component;
- }
- public Color ForeColor
- {
- get { return _NButton.ForeColor; }
- set { _NButton.ForeColor = value; }
- }
- public Color BaseColor
- {
- get { return _NButton.BaseColor; }
- set { _NButton.BaseColor = value; }
- }
- public Color BorderColor
- {
- get { return _NButton.BorderColor; }
- set { _NButton.BorderColor = value; }
- }
- public string Text
- {
- get { return _NButton.Text; }
- set { _NButton.Text = value; }
- }
- public Size Size
- {
- get { return _NButton.Size; }
- set { _NButton.Size = value; }
- }
- public Point Location
- {
- get { return _NButton.Location; }
- set { _NButton.Location = value; }
- }
- public void OriginalSize()
- {
- _NButton.Size = new Size(190, 50);
- }
- public override DesignerActionItemCollection GetSortedActionItems()
- {
- DesignerActionItemCollection items = new DesignerActionItemCollection
- {
- //Header Name
- new DesignerActionHeaderItem("Appearance"),
- // 1st BaseColor is property name (it must be exist).
- // 2nd BaseColor is the display name for the property.
- // Color is the category name we added from above.
- //"Gets or sets the background color." is the description for the property.
- new DesignerActionPropertyItem("BaseColor", "BaseColor", "Appearance", "Gets or sets the background color."),
- new DesignerActionPropertyItem("BorderColor", "BorderColor", "Appearance", "Gets or sets the border color."),
- new DesignerActionPropertyItem("ForeColor", "ForeColor", "Appearance", "Gets or sets the foreground color."),
- new DesignerActionPropertyItem("Text", "Text", "Appearance", "Gets or sets the text associated with the control."),
- new DesignerActionHeaderItem("Layout"),
- new DesignerActionPropertyItem("Location", "Location", "Layout", "Gets or sets the coordinates of the upper-left corner of the control relative to the upper-left corner of its container."),
- new DesignerActionPropertyItem("Size", "Size", "Layout", "Gets or sets the height and width of the control."),
- new DesignerActionHeaderItem("Misc"),
- new DesignerActionMethodItem(this, "OriginalSize","Set Original Size", "Misc", "Gets or sets the height and width of the control.")
- };
- return items;
- }
- }
Add Comment
Please, Sign In to add comment