📄 colortypeeditor.cs
字号:
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;
using System.Windows.Forms.Design;
namespace WroxDesign.Design
{
public class ColorTypeEditor : UITypeEditor
{
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return true;
}
/// <summary>
/// Paint your custom drawing in the output Graphics object recieved.
/// </summary>
public override void PaintValue(PaintValueEventArgs e)
{
WebControl control = e.Context.Instance as WebControl;
//Fills the left rectangle with a color.
e.Graphics.FillRegion(new SolidBrush(control.BackColor), new Region(e.Bounds));
//Draw a couple letters with the selected colorss
e.Graphics.DrawString("ab", new Font("Tahoma", 8,
FontStyle.Regular | (control.Font.Bold ? FontStyle.Bold : FontStyle.Regular) |
(control.Font.Italic ? FontStyle.Italic : FontStyle.Regular) |
(control.Font.Underline ? FontStyle.Underline : FontStyle.Regular)),
new SolidBrush(control.ForeColor), e.Bounds);
}
/// <summary>
/// Called upon edition of the property.
/// </summary>
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)
{
object retvalue = value;
IWindowsFormsEditorService srv = null;
//IToolboxService tool;
//System.ComponentModel.Design.ISelectionService sel;
//Get the editor service from the provider, to perform the dropdown.
if (provider != null)
srv = (IWindowsFormsEditorService)
provider.GetService(typeof(IWindowsFormsEditorService));
if (srv != null)
{
ColorTypeEditorControl editor =
new ColorTypeEditorControl((System.Drawing.Color)value,
context.Instance as WebControl);
srv.DropDownControl(editor);
return editor.SelectedColor;
}
return retvalue;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -