public class SVGEditor : UITypeEditor { private OpenFileDialog open_file_dialog = null; protected virtual void InitializeDialog(OpenFileDialog open_file_dialog) { open_file_dialog.Title = "Select an SVG File: "; open_file_dialog.Filter = "SVG File (*.svg)|*.svg"; } public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context) { return UITypeEditorEditStyle.Modal; } public override object EditValue(ITypeDescriptorContext context, IServiceProvider provider, object value) { if (provider is null || provider.GetService(typeof(IWindowsFormsEditorService)) is null) { return value; } Control ctrl = (Control)context.Instance; if (open_file_dialog is null) { open_file_dialog = new OpenFileDialog(); InitializeDialog(open_file_dialog); } if (value is string s) open_file_dialog.FileName = s; if (open_file_dialog.ShowDialog() == DialogResult.OK) { ctrl.Select(); ctrl.Capture = true; //[ The path of .resx file. ] /* ---> */ string resx_file_path = Environment.CurrentDirectory + "\\Properties\\Resources.resx"; //[ Generates resource's name by filename. ] string resource_name = Path.GetFileName(open_file_dialog.FileName); //[ Converts file's XmlDocument to string. ] XmlDocument xml_document = new XmlDocument { XmlResolver = null }; xml_document.Load(open_file_dialog.FileName); string svg_image_document = xml_document.InnerXml; //[ Adds resource to .resx file. ] Helpers.ResourcesOperator.Add_or_Update_Resource(resource_name, svg_image_document, resx_file_path); //[ Returns only the name of resource. ] return resource_name; } return value; } }
/* ---> */
Environment.CurrentDirectory
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)