webcontrolsizeeditor.cs

来自「ASP.NET服务器控件高级编程电子书」· CS 代码 · 共 44 行

CS
44
字号
using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;
using System.Windows.Forms.Design;
using System.Windows.Forms;

namespace WroxDesign.Design
{
	public class WebControlSizeEditor : UITypeEditor
	{
		public override UITypeEditorEditStyle GetEditStyle(ITypeDescriptorContext context)
		{
			return UITypeEditorEditStyle.Modal;
		}

		public override object EditValue(ITypeDescriptorContext context, 
			IServiceProvider provider, object value)
		{
			//Always return a valid value.
			object retvalue = value;

			IWindowsFormsEditorService srv = null;
			
			//Get the forms editor service from the provider, to display the form.
			if (provider != null)
				srv = (IWindowsFormsEditorService)
			provider.GetService(typeof(IWindowsFormsEditorService));

			if (srv != null)
			{
				WebControlSizeForm form = new WebControlSizeForm();
				form.CurrentSize = (WebControlSize)value;
				if (srv.ShowDialog(form) == DialogResult.OK)
					return form.CurrentSize;
			}
			
			return retvalue;
		}
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?