// COPYRIGHT (C) Tom. ALL RIGHTS RESERVED.
|
// THE AntdUI PROJECT IS AN WINFORM LIBRARY LICENSED UNDER THE Apache-2.0 License.
|
// LICENSED UNDER THE Apache License, VERSION 2.0 (THE "License")
|
// YOU MAY NOT USE THIS FILE EXCEPT IN COMPLIANCE WITH THE License.
|
// YOU MAY OBTAIN A COPY OF THE LICENSE AT
|
//
|
// http://www.apache.org/licenses/LICENSE-2.0
|
//
|
// UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, SOFTWARE
|
// DISTRIBUTED UNDER THE LICENSE IS DISTRIBUTED ON AN "AS IS" BASIS,
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
|
// SEE THE LICENSE FOR THE SPECIFIC LANGUAGE GOVERNING PERMISSIONS AND
|
// LIMITATIONS UNDER THE License.
|
// GITEE: https://gitee.com/antdui/AntdUI
|
// GITHUB: https://github.com/AntdUI/AntdUI
|
// CSDN: https://blog.csdn.net/v_132
|
// QQ: 17379620
|
|
using System;
|
using System.ComponentModel;
|
using System.Drawing;
|
using System.Drawing.Design;
|
using System.Windows.Forms.Design;
|
|
namespace AntdUI.Design
|
{
|
public class ColorEditor : UITypeEditor
|
{
|
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext? context) => UITypeEditorEditStyle.DropDown;
|
|
public override object? EditValue(ITypeDescriptorContext? context, IServiceProvider provider, object? value)
|
{
|
var service = provider.GetService(typeof(IWindowsFormsEditorService));
|
if (service is IWindowsFormsEditorService editorService)
|
{
|
var editorControl = new FrmColorEditor(value);
|
editorService.DropDownControl(editorControl);
|
return editorControl.Value;
|
}
|
return null;
|
}
|
|
public override bool GetPaintValueSupported(ITypeDescriptorContext? context) => true;
|
public override void PaintValue(PaintValueEventArgs e)
|
{
|
if (e.Value is Color color)
|
{
|
using var brush = new SolidBrush(color);
|
e.Graphics.FillRectangle(brush, e.Bounds);
|
}
|
}
|
}
|
}
|