1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using QuickRoute.BusinessEntities;
using System.Windows.Forms.Design;
using System.Drawing.Design;
using QuickRoute.PropertyControls;
namespace QuickRoute.Controls
{
public partial class GradientViewer : UserControl
{
private IWindowsFormsEditorService editorService = null;
private Gradient gradient;
// This constructor takes a Gradient value from the
// design-time environment, which will be used to display
// the initial state.
public GradientViewer(Gradient gradient, IWindowsFormsEditorService editorService)
{
// This call is required by the designer.
InitializeComponent();
// Cache the light shape value provided by the
// design-time environment.
this.gradient = gradient;
// Cache the reference to the editor service.
this.editorService = editorService;
}
// Gradient is the property for which this control provides
// a custom user interface in the Properties window.
[Category("Gradient")]
[Browsable(true)]
[EditorAttribute(typeof(GradientEditor), typeof(UITypeEditor))]
public Gradient Gradient
{
get
{
return this.gradient;
}
set
{
this.gradient = value;
}
}
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
gradient.Draw(this.CreateGraphics(), this.Bounds, 0, 1, Gradient.Direction.Horizontal);
}
}
internal class GradientEditor : UITypeEditor
{
IWindowsFormsEditorService editorService;
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (provider != null)
{
editorService =
provider.GetService(
typeof(IWindowsFormsEditorService))
as IWindowsFormsEditorService;
}
if (editorService != null)
{
GradientEditorControl editorControl = new GradientEditorControl((Gradient)value, editorService);
editorService.DropDownControl(editorControl);
}
return value;
}
// This method indicates to the design environment that
// the type editor will paint additional content in the
// LightShape entry in the PropertyGrid.
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return true;
}
// This method paints a graphical representation of the
// selected value of the LightShpae property.
public override void PaintValue(PaintValueEventArgs e)
{
Gradient gradient = (Gradient)e.Value;
gradient.Draw(e.Graphics, e.Bounds, 0, 1, Gradient.Direction.Horizontal);
}
}
}
|