using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace GeoSigma.SigmaDrawerStyle
{
///
/// 曲线样式 UI 界面
///
public class PropertyEditorWellCurveStyle : UITypeEditor
{
///
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
///
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
if (!(value is WellLineStyle style))
{
return value;
}
IWindowsFormsEditorService edSvc = provider?.GetService(typeof(IWindowsFormsEditorService)) as IWindowsFormsEditorService;
if (edSvc == null)
{
return value;
}
using (var editorForm = new WellCurveStyleEditForm(style))
{
if (edSvc.ShowDialog(editorForm) == DialogResult.OK)
{
WellLineStyle retStyle = new WellLineStyle();
retStyle.Color = editorForm.style.Color;
retStyle.Width = editorForm.style.Width;
retStyle.Style = editorForm.style.Style;
return retStyle;
}
}
return value;
}
///
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return true;
}
///
public override void PaintValue(PaintValueEventArgs e)
{
if (e.Value is WellLineStyle style)
{
var g = e.Graphics;
var rect = e.Bounds;
using (var pen = new Pen(style.Color, (float)Math.Max(1, style.Width)))
{
// 设置 DashStyle(除非 Solid 属性强制为实线)
pen.DashStyle = DashStyle.Solid;
// 居中画线
int y = rect.Top + (rect.Height / 2);
g.DrawLine(pen, rect.Left, y, rect.Right, y);
}
}
}
}
}