⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 toolboxservice.cs

📁 c#源代码
💻 CS
📖 第 1 页 / 共 2 页
字号:
						}
						list = (ArrayList)toolboxByHost[ALL_HOSTS];
						if (list != null && list.Contains(item)) {
							return item;
						}
					}
				}
			}
			return null;
		}
		
		public ToolboxItem GetSelectedToolboxItem()
		{
			return selectedItem;
		}
		
		public ToolboxItem GetSelectedToolboxItem(IDesignerHost host)
		{
			IList list = (IList)toolboxByHost[host];
			if (list != null && list.Contains(selectedItem)) {
				return selectedItem;
			}
			
			list = (IList)toolboxByHost[ALL_HOSTS];
			if (list.Contains(selectedItem)) {
				return selectedItem;
			}
			return null;
		}
		
		public ToolboxItemCollection GetToolboxItems()
		{
			ToolboxItem[] items = new ToolboxItem[toolboxItems.Count];
			toolboxItems.CopyTo(items);
			return new ToolboxItemCollection(items);
		}
		
		public ToolboxItemCollection GetToolboxItems(string category)
		{
			if (category == null) {
				category = ALL_CATEGORIES;
			}
			
			ArrayList list = (ArrayList)toolboxByCategory[category];
			list.Add((ArrayList)toolboxByCategory[ALL_CATEGORIES]);
			ToolboxItem[] items = new ToolboxItem[list.Count];
			toolboxItems.CopyTo(items);
			return new ToolboxItemCollection(items);
		}
		
		public ToolboxItemCollection GetToolboxItems(string category, IDesignerHost host)
		{
			if (category == null) {
				category = ALL_CATEGORIES;
			}
			
			ArrayList hList = null;
			
			if (host == null) {
				hList = (ArrayList)toolboxByHost[ALL_HOSTS];
			} else {
				hList = (ArrayList)toolboxByHost[host];
			}
			
			ArrayList cList = (ArrayList)toolboxByCategory[category];
			ArrayList list = new ArrayList();
			
			foreach (ToolboxItem item in hList) {
				if (cList.Contains(item)) {
					list.Add(item);
				}
			}
			
			ToolboxItem[] items = new ToolboxItem[list.Count];
			toolboxItems.CopyTo(items);
			return new ToolboxItemCollection(items);
		}
		
		public ToolboxItemCollection GetToolboxItems(IDesignerHost host)
		{
			ArrayList hList = null;
			
			if(host == null) {
				hList = (ArrayList)toolboxByHost[ALL_HOSTS];
			} else {
				hList = (ArrayList)toolboxByHost[host];
			}
			ArrayList list = (ArrayList)toolboxByHost[host];
			list.Add((ArrayList)toolboxByHost[ALL_HOSTS]);
			ToolboxItem[] items = new ToolboxItem[list.Count];
			toolboxItems.CopyTo(items);
			return new ToolboxItemCollection(items);
		}
		
		public bool IsSupported(object serializedObject, ICollection filterAttributes)
		{
			return false;
		}
		
		public bool IsSupported(object serializedObject, IDesignerHost host)
		{
			return false;
		}
		
		public bool IsToolboxItem(object serializedObject)
		{
			if (serializedObject is System.Windows.Forms.IDataObject)
			{
				if (((System.Windows.Forms.IDataObject)serializedObject).GetDataPresent(typeof(ToolboxItem)))
					return true;
			}
			return false;
		}
		
		public bool IsToolboxItem(object serializedObject, IDesignerHost host)
		{
			// needed for Toolbox drag & drop
			if (serializedObject is System.Windows.Forms.IDataObject)
			{
				if (((System.Windows.Forms.IDataObject)serializedObject).GetDataPresent(typeof(ToolboxItem)))
				{
					ToolboxItem item = (ToolboxItem) ((System.Windows.Forms.IDataObject)serializedObject).GetData(typeof(ToolboxItem));
					if(host != null)
					{
						ArrayList list = (ArrayList)toolboxByHost[host];
						if (list != null && list.Contains(item))
						  return true;
						list = (ArrayList)toolboxByHost[ALL_HOSTS];
						if (list != null && list.Contains(item))
							return true;
					}
				}
			}
			return false;
		}
		
		public void Refresh()
		{
			//System.Console.WriteLine("\tDefaultToolboxService:Refresh()");
		}
		
		public void RemoveCreator(string format)
		{
			RemoveCreator(format, null);
		}
		
		public void RemoveCreator(string format, IDesignerHost host)
		{
			if (host == null) {
				creators.Remove(format);
			} else {
				HybridDictionary creatorsDict = creatorsByHost[host] as HybridDictionary;
				if (creatorsDict != null) {
					creatorsDict.Remove(format);
					if (creatorsDict.Count == 0)
					creatorsByHost.Remove(host);
				}
			}
		}
		
		public void RemoveToolboxItem(ToolboxItem toolboxItem)
		{
			toolboxItems.Remove(toolboxItem);
			ArrayList list = (ArrayList)toolboxByCategory[ALL_CATEGORIES];
			list.Remove(toolboxItem);
			list = (ArrayList)toolboxByHost[ALL_HOSTS];
			list.Remove(toolboxItem);
			FireToolboxItemRemoved(toolboxItem, null, null);
		}
		
		public void RemoveToolboxItem(ToolboxItem toolboxItem, string category)
		{
			toolboxItems.Remove(toolboxItem);
			ArrayList list = (ArrayList)toolboxByCategory[category];
			list.Remove(toolboxItem);
			FireToolboxItemRemoved(toolboxItem, category, null);
		}
		
		public void SelectedToolboxItemUsed()
		{
			FireSelectedItemUsed();
		}
		
		public object SerializeToolboxItem(ToolboxItem toolboxItem)
		{
			return null;
		}
		
		public bool SetCursor()
		{
			if (selectedItem == null) {
				return false;
			}
			if (selectedItem.DisplayName == "Pointer") {
				return false;
			}
			return true;
		}
		
		public void SetSelectedToolboxItem(ToolboxItem toolboxItem)
		{
			if (toolboxItem != selectedItem) {
				FireSelectedItemChanging();
				selectedItem = toolboxItem;
				FireSelectedItemChanged();
			}
		}
		
		// Event helpers
		void FireSelectedCategoryChanging()
		{
			if (SelectedCategoryChanging != null) {
				SelectedCategoryChanging(this, EventArgs.Empty);
			}
		}
		
		void FireSelectedItemChanged()
		{
			if (SelectedItemChanged != null) {
				SelectedItemChanged(this, EventArgs.Empty);
			}
		}
		
		void FireSelectedItemChanging()
		{
			if (SelectedItemChanging != null) {
				SelectedItemChanging(this, EventArgs.Empty);
			}
		}
		
		void FireSelectedCategoryChanged()
		{
			if (SelectedCategoryChanged != null) {
				SelectedCategoryChanged(this, EventArgs.Empty);
			}
		}
		
		void FireSelectedItemUsed()
		{
			if (SelectedItemUsed != null) {
				SelectedItemUsed(this, EventArgs.Empty);
			}
		}
		
		void FireToolboxItemAdded(ToolboxItem item, string category, IDesignerHost host)
		{
			if (ToolboxItemAdded != null) {
				ToolboxItemAdded(this, new ToolboxEventArgs(item, category, host));
			}
		}
		
		void FireToolboxItemRemoved(ToolboxItem item, string category, IDesignerHost host)
		{
			if (ToolboxItemAdded != null) {
				ToolboxItemRemoved(this, new ToolboxEventArgs(item, category, host));
			}
		}
		
		// Events
		public event EventHandler SelectedCategoryChanging;
		public event EventHandler SelectedCategoryChanged;
		public event EventHandler SelectedItemChanging;
		public event EventHandler SelectedItemChanged;
		public event EventHandler SelectedItemUsed;
		public event ToolboxEventHandler ToolboxItemAdded;
		public event ToolboxEventHandler ToolboxItemRemoved;
	}
}

⌨️ 快捷键说明

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