You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kev/Drawer/UCDraw/SigmaDrawerWellStyle/PropertyEditorWellCurveStyl...

79 lines
2.3 KiB
C#

1 month ago
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
{
/// <summary>
/// 曲线样式 UI 界面
/// </summary>
public class PropertyEditorWellCurveStyle : UITypeEditor
{
/// <inheritdoc/>
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.Modal;
}
/// <inheritdoc/>
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)
{
return new WellLineStyle()
{
Color = style.Color,
Width = style.Width,
Style = style.Style,
};
}
}
return value;
}
/// <inheritdoc/>
public override bool GetPaintValueSupported(ITypeDescriptorContext context)
{
return true;
}
/// <inheritdoc/>
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, 1))
{
// 设置 DashStyle除非 Solid 属性强制为实线)
pen.DashStyle = DashStyle.Solid;
// 居中画线
int y = rect.Top + (rect.Height / 2);
g.DrawLine(pen, rect.Left, y, rect.Right, y);
}
}
}
}
}