wroxstylerconverter.cs

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

CS
65
字号
using System;
using System.IO;
using System.Web.UI;
using System.Web.UI.Design;
using System.Web.UI.WebControls;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;

namespace WroxDesign.Design
{
	public class WroxStylerConverter : TypeConverter
	{
		private ArrayList _stylers = new ArrayList();

		public WroxStylerConverter()
		{ 
		}

		public override bool GetStandardValuesSupported(
			ITypeDescriptorContext context) 
		{
			if (!_stylers.Contains(context.Instance))
				_stylers.Add(context.Instance);
			return true;
		}

		public override bool GetStandardValuesExclusive(
			ITypeDescriptorContext context) 
		{
			return true;
		}

		public override StandardValuesCollection GetStandardValues(
			ITypeDescriptorContext context) 
		{
			System.Collections.ArrayList list = new System.Collections.ArrayList();

			foreach (IComponent comp in context.Container.Components)
				if (comp is WroxButton) list.Add(((WroxButton)comp).ID);

			IComponentChangeService svc = context.GetService(
				typeof(IComponentChangeService)) as IComponentChangeService;			

			svc.ComponentRename += new ComponentRenameEventHandler(OnRename);
			svc.ComponentRemoved += new ComponentEventHandler(OnRemove);
			return new StandardValuesCollection(list);
		}

		private void OnRemove(object sender, ComponentEventArgs e)
		{
			if (_stylers.Contains(e.Component))
				_stylers.Remove(e.Component);
		}

		private void OnRename(object sender, ComponentRenameEventArgs e)
		{
			if (e.Component is WroxButton)
				foreach (WroxStyler st in _stylers)
					if (e.OldName == st.RelatedButtonID)
						TypeDescriptor.GetProperties(st)
							["RelatedButtonID"].SetValue(st, e.NewName);
		}
	}
}

⌨️ 快捷键说明

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