www.pudn.com > WebPager.rar > DataPagerEditor.cs, change:2005-01-24,size:1797b


using System; 
using System.Web; 
using System.Reflection; 
using System.Drawing.Design; 
using System.ComponentModel; 
using System.Windows.Forms; 
using System.Windows.Forms.Design; 
 
namespace Hooyee.WebControls { 
	/// <summary> 
	/// 翻页控件属性编辑器。 
	/// </summary> 
	/// <version> 
	/// 20040827	Kriss 
	/// </version> 
	internal sealed class DataPagerEditor : UITypeEditor { 
		/// <summary> 
		/// 翻页子控件公共接口名 
		/// </summary> 
		private const string PAGER_INTERFACE = "IDataPager"; 
		private static ListBox uiPagers = null; 
		private static IWindowsFormsEditorService edSvc = null; 
 
		static DataPagerEditor() { 
			uiPagers = new ListBox(); 
			uiPagers.BorderStyle = System.Windows.Forms.BorderStyle.None; 
 
			// 从当前程序集获得所有实现翻页公共接口的翻页控件名 
			Assembly assembly = typeof( DataPagerEditor ).Assembly; 
			foreach ( Type type in assembly.GetTypes() ) { 
				if ( type.GetInterface( PAGER_INTERFACE ) != null 
					&& !type.IsAbstract ) { 
					uiPagers.Items.Add( type.Name ); 
				} 
			} 
 
			uiPagers.SelectedValueChanged += new EventHandler( OnClick ); 
		} 
 
		public override UITypeEditorEditStyle GetEditStyle( ITypeDescriptorContext context ) { 
			return UITypeEditorEditStyle.DropDown; 
		} 
 
		public override object EditValue( ITypeDescriptorContext context , IServiceProvider provider , object value ) { 
			if ( provider == null ) 
				return null; 
 
			edSvc = ( IWindowsFormsEditorService ) 
				provider.GetService( typeof( IWindowsFormsEditorService ) ); 
 
			if ( edSvc == null ) 
				return null; 
 
			edSvc.DropDownControl( uiPagers ); 
			value = uiPagers.SelectedItem.ToString(); 
			return value; 
		} 
 
		private static void OnClick( object sender , System.EventArgs e ) { 
			edSvc.CloseDropDown(); 
		} 
	} 
}