using Newtonsoft.Json;
|
using System;
|
using System.Collections.Generic;
|
using System.ComponentModel;
|
using System.Drawing.Design;
|
using System.IO;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
using System.Windows.Forms;
|
using System.Windows.Forms.Design;
|
|
namespace Hydro.MapView
|
{
|
public class DlTemplateEditor : UITypeEditor
|
{
|
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
|
{
|
return UITypeEditorEditStyle.DropDown;
|
}
|
|
public override object EditValue(ITypeDescriptorContext context, IServiceProvider serviceProvider, object value)
|
{
|
if (context != null && serviceProvider != null)
|
{
|
IWindowsFormsEditorService editorService = (IWindowsFormsEditorService)serviceProvider.GetService(typeof(IWindowsFormsEditorService));
|
|
if (editorService != null)
|
{
|
var filePath = Path.Combine(Directory.GetCurrentDirectory(), "Data\\WaterEquivalent.Json");
|
List<string> wds = new List<string>();
|
if (File.Exists(filePath))
|
{
|
var json = File.ReadAllText(filePath);
|
if (!string.IsNullOrEmpty(json))
|
{
|
var w = JsonConvert.DeserializeObject<List<EquivalentTemplateModel>>(json);
|
if (w != null)
|
{
|
foreach (var item in w)
|
{
|
wds.Add(item.Name);
|
}
|
}
|
}
|
}
|
// 创建下拉列表
|
ComboBox comboBox = new ComboBox();
|
comboBox.Items.AddRange(wds.ToArray());
|
|
// 显示下拉列表
|
editorService.DropDownControl(comboBox);
|
|
// 返回选中的值
|
value = comboBox.SelectedItem;
|
}
|
}
|
|
return value;
|
}
|
}
|
}
|