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

📄 wxdactivitytool.cs

📁 基于微软WF开发的工作流全套实例源码
💻 CS
📖 第 1 页 / 共 2 页
字号:
using System.Runtime.Serialization.Formatters.Binary;
using System.Collections;
using System.ComponentModel.Design;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Diagnostics;
using System.Drawing.Design;
using System.Drawing.Text;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Remoting;
using System.Runtime.Serialization.Formatters;
using System.Text;
using System.Windows.Forms.ComponentModel;
using System.Windows.Forms.Design;
using System.Windows.Forms;
using System;
using System.Workflow.Activities;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;


namespace wxwinter.wf.Design
{
    [ToolboxItem(false)]
    public class wxdActivityTool : Panel, IToolboxService
    {
        private IServiceProvider provider;
        private Hashtable customCreators;
        private Type currentSelection;
        private ListBox listBox = new ListBox();

        private string activityToolItemFile;

        public string ActivityToolItemFile
        {
            get { return activityToolItemFile; }
            set { activityToolItemFile = value; }
        }


        //创建工具栏的Activiey组件项
        public wxdActivityTool(IServiceProvider provider, string activityToolItemFile)
        {
            this.activityToolItemFile = activityToolItemFile;
            this.provider = provider;

            Text = "工具栏";
            Size = new System.Drawing.Size(224, 350);

            listBox.Dock = DockStyle.Fill;
            listBox.IntegralHeight = false;
            listBox.ItemHeight = 20;
            listBox.DrawMode = DrawMode.OwnerDrawFixed;
            listBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
            listBox.BackColor = SystemColors.Window;
            listBox.ForeColor = SystemColors.ControlText;
            listBox.MouseMove += new MouseEventHandler(OnListBoxMouseMove);
            Controls.Add(listBox);

            listBox.DrawItem += new DrawItemEventHandler(this.OnDrawItem);
            listBox.SelectedIndexChanged += new EventHandler(this.OnListBoxClick);

            AddToolboxEntries(listBox);
        }

        public void AddCreator(ToolboxItemCreatorCallback creator, string format)
        {
            AddCreator(creator, format, null);
        }

        public void AddCreator(ToolboxItemCreatorCallback creator, string format, IDesignerHost host)
        {
            if (creator == null || format == null)
            {
                throw new ArgumentNullException(creator == null ? "creator" : "format");
            }

            if (customCreators == null)
            {
                customCreators = new Hashtable();
            }
            else
            {
                string key = format;

                if (host != null) key += ", " + host.GetHashCode().ToString();

                if (customCreators.ContainsKey(key))
                {
                    throw new Exception("There is already a creator registered for the format '" + format + "'.");
                }
            }

            customCreators[format] = creator;
        }

        public void AddLinkedToolboxItem(ToolboxItem toolboxItem, IDesignerHost host)
        {
        }

        public void AddLinkedToolboxItem(ToolboxItem toolboxItem, string category, IDesignerHost host)
        {
        }

        public virtual void AddToolboxItem(ToolboxItem toolboxItem)
        {
        }

        public virtual void AddToolboxItem(ToolboxItem toolboxItem, IDesignerHost host)
        {
        }

        public virtual void AddToolboxItem(ToolboxItem toolboxItem, string category)
        {
        }

        public virtual void AddToolboxItem(ToolboxItem toolboxItem, string category, IDesignerHost host)
        {
        }

        public CategoryNameCollection CategoryNames
        {
            get
            {
                return new CategoryNameCollection(new string[] { "Workflow" });
            }
        }

        public string SelectedCategory
        {
            get
            {
                return "Workflow";
            }
            set
            {
            }
        }

        private ToolboxItemCreatorCallback FindToolboxItemCreator(IDataObject dataObj, IDesignerHost host, out string foundFormat)
        {
            foundFormat = string.Empty;

            ToolboxItemCreatorCallback creator = null;
            if (customCreators != null)
            {
                IEnumerator keys = customCreators.Keys.GetEnumerator();
                while (keys.MoveNext())
                {
                    string key = (string)keys.Current;
                    string[] keyParts = key.Split(new char[] { ',' });
                    string format = keyParts[0];

                    if (dataObj.GetDataPresent(format))
                    {
                        // Check to see if the host matches.
                        if (keyParts.Length == 1 || (host != null && host.GetHashCode().ToString().Equals(keyParts[1])))
                        {
                            creator = (ToolboxItemCreatorCallback)customCreators[format];
                            foundFormat = format;
                            break;
                        }
                    }
                }
            }

            return creator;
        }

        public virtual ToolboxItem GetSelectedToolboxItem()
        {
            ToolboxItem toolClass = null;
            if (this.currentSelection != null)
            {
                try
                {
                    toolClass = wxdActivityTool.GetToolboxItem(this.currentSelection);
                }
                catch (TypeLoadException)
                {
                }
            }

            return toolClass;
        }

        public virtual ToolboxItem GetSelectedToolboxItem(IDesignerHost host)
        {
            return GetSelectedToolboxItem();
        }

        public object SerializeToolboxItem(ToolboxItem toolboxItem)
        {
            DataObject dataObject = new DataObject();
            dataObject.SetData(typeof(ToolboxItem), toolboxItem);
            return dataObject;
        }

        public ToolboxItem DeserializeToolboxItem(object dataObject)
        {
            return DeserializeToolboxItem(dataObject, null);
        }

        public ToolboxItem DeserializeToolboxItem(object data, IDesignerHost host)
        {
            IDataObject dataObject = data as IDataObject;

            if (dataObject == null)
            {
                return null;
            }

            ToolboxItem t = (ToolboxItem)dataObject.GetData(typeof(ToolboxItem));

            if (t == null)
            {
                string format;
                ToolboxItemCreatorCallback creator = FindToolboxItemCreator(dataObject, host, out format);

                if (creator != null)
                {
                    return creator(dataObject, format);
                }
            }

            return t;
        }

        public ToolboxItemCollection GetToolboxItems()
        {
            return new ToolboxItemCollection(new ToolboxItem[0]);
        }

        public ToolboxItemCollection GetToolboxItems(IDesignerHost host)
        {
            return new ToolboxItemCollection(new ToolboxItem[0]);
        }

        public ToolboxItemCollection GetToolboxItems(string category)
        {
            return new ToolboxItemCollection(new ToolboxItem[0]);
        }

        public ToolboxItemCollection GetToolboxItems(string category, IDesignerHost host)
        {
            return new ToolboxItemCollection(new ToolboxItem[0]);
        }

        public bool IsSupported(object data, IDesignerHost host)
        {
            return true;
        }

        public bool IsSupported(object serializedObject, ICollection filterAttributes)
        {
            return true;
        }

        public bool IsToolboxItem(object dataObject)
        {
            return IsToolboxItem(dataObject, null);
        }

        public bool IsToolboxItem(object data, IDesignerHost host)
        {
            IDataObject dataObject = data as IDataObject;
            if (dataObject == null)
                return false;

⌨️ 快捷键说明

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