using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Design; using System.Drawing.Drawing2D; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using System.Windows.Forms.Design; using GeoSigmaDrawLib; using SymbolLibInterface; namespace GeoSigma.SigmaDrawerStyle { //[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")] public class PropertyEditorSymbol : UITypeEditor { /// /// Initializes a new instance of the class. /// public PropertyEditorSymbol() { } // Indicates whether the UITypeEditor provides a form-based (modal) dialog, // drop down dialog, or no UI outside of the properties window. public override UITypeEditorEditStyle GetEditStyle(System.ComponentModel.ITypeDescriptorContext context) { return UITypeEditorEditStyle.Modal; } // Displays the UI for value selection. public override object EditValue(System.ComponentModel.ITypeDescriptorContext context, System.IServiceProvider provider, object value) { // Uses the IWindowsFormsEditorService to display a // drop-down UI in the Properties window. IWindowsFormsEditorService edSvc = (IWindowsFormsEditorService)provider.GetService(typeof(IWindowsFormsEditorService)); if (edSvc != null) { // Display an angle selection control and retrieve the value. SymbolNameWrapper wrapper = value as SymbolNameWrapper; GeoSigmaXY geo = wrapper.DrawerGeo as GeoSigmaXY; //SymbolLibManager.FrmSymbolSelect frm = new SymbolLibManager.FrmSymbolSelect(geo); string strLibraryPath = string.Empty; geo.GetLibraryPath(ref strLibraryPath); Form frmSymbol = SymbolHelp.CreateSymbolSelectForm(geo, strLibraryPath, AcceptSymbolName); System.Windows.Forms.DialogResult result = edSvc.ShowDialog(frmSymbol); if (result == System.Windows.Forms.DialogResult.OK) { // Return the value in the data format. SymbolNameWrapper wrapperNew = new SymbolNameWrapper(); wrapperNew.DrawerGeo = geo; //wrapperNew.SymbolName = frm.SelectedSymbolName; wrapperNew.SymbolName = selectedSymbol; //context.PropertyDescriptor.SetValue(context.Instance, wrapperNew); //// Notify container that value has been changed //context.OnComponentChanged(); return wrapperNew; } else { return value; } } return value; } string selectedSymbol = string.Empty; private string AcceptSymbolName(string symbolName) { return selectedSymbol = symbolName; } // Draws a representation of the property's value. public override void PaintValue(PaintValueEventArgs e) { if (!(e.Value is SymbolNameWrapper)) { base.PaintValue(e); return; } SymbolNameWrapper symbolWrapper = e.Value as SymbolNameWrapper; if (symbolWrapper == null || string.IsNullOrEmpty(symbolWrapper.SymbolName) || symbolWrapper.DrawerGeo == null) { base.PaintValue(e); return; } //// remove the lines (you cannot draw on these lines anymore) // e.Graphics.ExcludeClip( // new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, 1)); // e.Graphics.ExcludeClip( // new Rectangle(e.Bounds.X, e.Bounds.Y, 1, e.Bounds.Height)); // e.Graphics.ExcludeClip( // new Rectangle(e.Bounds.Width, e.Bounds.Y, 1, e.Bounds.Height)); // e.Graphics.ExcludeClip( // new Rectangle(e.Bounds.X, e.Bounds.Height, e.Bounds.Width, 1)); int nWidth = Math.Min(e.Bounds.Width, e.Bounds.Height); int nX = e.Bounds.X + ((e.Bounds.Width - nWidth) / 2); int nY = e.Bounds.Y + ((e.Bounds.Height - nWidth) / 2); string strName = symbolWrapper.SymbolName; Bitmap bmp = new Bitmap(nWidth, nWidth); Graphics gBmp = Graphics.FromImage(bmp); IntPtr pBmpDC = gBmp.GetHdc(); IntPtr pXy = IntPtr.Zero; ((GeoSigmaXY)(symbolWrapper.DrawerGeo)).DrawerDrawSymbolFill(strName, pBmpDC, nWidth, nWidth, ref pXy); gBmp.ReleaseHdc(); e.Graphics.DrawImage(bmp, nX, nY, nWidth, nWidth); bmp.Dispose(); } // Indicates whether the UITypeEditor supports painting a // representation of a property's value. public override bool GetPaintValueSupported(System.ComponentModel.ITypeDescriptorContext context) { return true; } } }