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 { /// /// 填充符号 /// public class PropertyEditorFillSymbol : UITypeEditor { /// public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context) { return UITypeEditorEditStyle.DropDown; } /// 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; } /// 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); } } } } /// 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; } } }