📄 selectionlayerseditor.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Design;
using System.Windows.Forms;
using System.Windows.Forms.ComponentModel;
using System.Windows.Forms.Design;
using System.Collections;
namespace SelectToolTask
{
class SelectionLayersEditor: UITypeEditor
{
// Sets up and displays the dialog in Visual Studio, and gets the result
public override object EditValue(ITypeDescriptorContext context,
IServiceProvider provider, object value)
{
if ((context != null) && (provider != null))
{
System.Web.UI.Control ctrl = context.Instance as System.Web.UI.Control;
if (ctrl == null)
return value;
// Get layers even when editor is accessed from the task's Properties dialog
SelectToolTask grSelTask = context.Instance as SelectToolTask;
string[] allLayers = null;
string[] invalidServices = null;
if (grSelTask != null)
{
// Get a list of all queryable layers
allLayers = GetLayers(grSelTask, out invalidServices);
}
// split selected layers into array (these were passed in as a method argument)
string[] selectedLayers = null;
if (!String.IsNullOrEmpty(value as string))
selectedLayers = ((string)value).Split(new string[] { "::" }, StringSplitOptions.None);
SelectionLayerEditorForm form = new SelectionLayerEditorForm(
selectedLayers, allLayers, invalidServices);
if (form.ShowDialog() == DialogResult.OK)
{
selectedLayers = form.SelectableLayers;
// join layers into single string
value = String.Join("::", selectedLayers);
}
}
return value;
}
/// <summary>
/// Gets the editor style used by the EditValue method
/// </summary>
/// <param name="context">An ITypeDescriptorContext that can be used
/// to gain additional context information<see cref="System.ComponentModel.ITypeDescriptorContext"/></param>
/// <returns>If the context is not null, the Style will
/// always be returned as Modal, otherwise will return a default edit style</returns>
public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
{
if (context != null)
{
return UITypeEditorEditStyle.Modal;
}
return base.GetEditStyle(context);
}
// Gets a list of queryable layers associated with the Map control used in the task
private string[] GetLayers(SelectToolTask grSelTask,
out string[] invalidServices)
{
string[] layers = null;
invalidServices = new string[0];
string idStringDelim = "___";
ESRI.ArcGIS.ADF.Web.UI.WebControls.Map mapControl =
Utilities.FindControlRecursive(grSelTask.Page, grSelTask.Map)
as ESRI.ArcGIS.ADF.Web.UI.WebControls.Map;
// if Map property is null/blank, find first Map control on Page
if (mapControl == null)
{
List<System.Web.UI.Control> maps = Utilities.FindControls(
typeof(ESRI.ArcGIS.ADF.Web.UI.WebControls.Map), grSelTask.Page.Controls);
if (maps.Count > 0)
mapControl = maps[0] as ESRI.ArcGIS.ADF.Web.UI.WebControls.Map;
}
if (mapControl != null)
{
// get layers, also any invalid resources
System.Web.UI.WebControls.ListItem[] lyrItems =
Utilities.GetQueryLayers(mapControl, null,
idStringDelim, out invalidServices);
layers = new string[lyrItems.Length];
for (int i = 0; i < lyrItems.Length; i++)
layers[i] = lyrItems[i].Text;
}
return layers;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -