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/SigmaDrawerWellElement/PropertyEditorFillSymbol.cs

92 lines
2.6 KiB
C#

1 month ago
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Windows.Forms.Design;
using GeoSigma.SigmaDrawerStyle;
using GeoSigmaDrawLib;
namespace GeoSigma.SigmaDrawerElement
{
/// <summary>
/// 填充符号
/// </summary>
public class PropertyEditorFillSymbol : UITypeEditor
{
/// <inheritdoc/>
public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context)
{
return UITypeEditorEditStyle.DropDown;
}
/// <inheritdoc/>
public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value)
{
IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService));
if (edSvc == null)
{
return base.EditValue(context, provider, value);
}
var listBox = new MarkListBox();
listBox.SelectedIndexChanged += (s, e) =>
{
edSvc.CloseDropDown();
};
edSvc.DropDownControl(listBox);
return listBox.SelectedItem != null ? listBox.SelectedItem.ToString() : string.Empty;
}
/// <inheritdoc/>
public override void PaintValue(PaintValueEventArgs e)
{
if (e.Value is string name)
{
Bitmap bitmap = GetBitmap(e.Value.ToString(), e.Bounds.Width, e.Bounds.Height);
if (bitmap != null)
{
using (bitmap)
{
e.Graphics.DrawImage(bitmap, e.Bounds);
}
}
}
}
/// <inheritdoc/>
public override bool GetPaintValueSupported(System.ComponentModel.ITypeDescriptorContext context)
{
return true;
}
private Bitmap GetBitmap(string name, int width, int height)
{
Bitmap bitmap = new Bitmap(width, height);
using (Graphics image = Graphics.FromImage(bitmap))
{
IntPtr hdc = image.GetHdc();
bool success = false;
try
{
success = GeoSigmaWellPoleXY.GetDrawCurveFillSymbol(name, hdc, width, height);
}
finally
{
image.ReleaseHdc(hdc);
}
if (!success)
{
bitmap.Dispose();
return null;
}
}
return bitmap;
}
}
}