Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.ComponentModel;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Runtime.InteropServices;
- namespace System.Windows.Forms {
- [ComVisible(false)]
- public class GradientPanel:Panel {
- GradientPanelProperties _properties;
- public GradientPanel() {
- _properties = new GradientPanelProperties();
- _properties.GradientMode = LinearGradientMode.Horizontal;
- _properties.LeftColor = Color.Black;
- _properties.RightColor = Color.White;
- }
- protected override void OnResize(EventArgs eventargs) {
- if(base.DesignMode) {
- base.OnResize(eventargs);
- return;
- }
- this.Invalidate(true);
- }
- protected override void OnPaint(PaintEventArgs e) {
- this.PaintGradient(e.Graphics,e.ClipRectangle);
- }
- protected override void OnPaintBackground(PaintEventArgs pevent) {
- if(base.DesignMode) {
- this.PaintPanel(pevent.Graphics,pevent.ClipRectangle);
- }
- }
- protected void PaintGradient(Graphics graphics,Rectangle clipRectangle) {
- if(((graphics != null) && ((clipRectangle.Width != 0) && (clipRectangle.Height != 0))) && ((base.ClientRectangle.Width != 0) && (base.ClientRectangle.Height != 0))) {
- using(LinearGradientBrush brush = new LinearGradientBrush(base.ClientRectangle,this.LeftColor,this.RightColor,this.GradientMode)) {
- if(this.BellShape) {
- brush.SetSigmaBellShape(0.5f,1f);
- }
- else if(this.TriangleShape) {
- brush.SetBlendTriangularShape(0.5f,1f);
- }
- graphics.FillRectangle(brush,clipRectangle);
- }
- }
- }
- public virtual void PaintPanel(Graphics graphics,Rectangle clipRectangle) {
- this.PaintGradient(graphics,clipRectangle);
- }
- [Category("_GradientPanel")]
- [Description("Gradient Panel Properties")]
- public GradientPanelProperties Properties {
- get {
- return _properties;
- }
- set {
- _properties = value ?? new GradientPanelProperties();
- }
- }
- [Category("_GradientPanel")]
- [Description("Apply a bell-shaped distribution to the gradient?"),DefaultValue(false)]
- public bool BellShape {
- get {
- return _properties.BellShape;
- }
- set {
- _properties.BellShape = value;
- }
- }
- [Category("_GradientPanel")]
- [Description("The LinearGradientMode enumeration describing the gradient."),DefaultValue(0)]
- public LinearGradientMode GradientMode {
- get {
- return _properties.GradientMode;
- }
- set {
- _properties.GradientMode = value;
- }
- }
- [Category("_GradientPanel")]
- [Description("Starting color for the gradient"),DefaultValue(typeof(Color),"Black")]
- public Color LeftColor {
- get {
- return _properties.LeftColor;
- }
- set {
- _properties.LeftColor = value;
- base.Invalidate();
- }
- }
- [Category("_GradientPanel")]
- [DefaultValue(typeof(Color),"White"),Description("Ending color for the gradient")]
- public Color RightColor {
- get {
- return _properties.RightColor;
- }
- set {
- _properties.RightColor = value;
- base.Invalidate();
- }
- }
- [Category("_GradientPanel")]
- [Description("Apply a triangle-shaped distribution to the gradient?"),DefaultValue(false)]
- public bool TriangleShape {
- get {
- return _properties.TriangleShape;
- }
- set {
- _properties.TriangleShape = value;
- }
- }
- public class GradientPanelProperties {
- public bool BellShape { get; set; }
- public LinearGradientMode GradientMode { get; set; }
- public Color LeftColor { get; set; }
- public Color RightColor { get; set; }
- public bool TriangleShape { get; set; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment