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

📄 wxdactivitytool.cs

📁 基于微软WF开发的工作流全套实例源码
💻 CS
📖 第 1 页 / 共 2 页
字号:
            if (dataObject.GetDataPresent(typeof(ToolboxItem)))
            {
                return true;
            }
            else
            {
                string format;
                ToolboxItemCreatorCallback creator = FindToolboxItemCreator(dataObject, host, out format);
                if (creator != null)
                    return true;
            }

            return false;
        }

        public new void Refresh()
        {
        }

        public void RemoveCreator(string format)
        {
            RemoveCreator(format, null);
        }

        public void RemoveCreator(string format, IDesignerHost host)
        {
            if (format == null)
                throw new ArgumentNullException("format");

            if (customCreators != null)
            {
                string key = format;
                if (host != null)
                    key += ", " + host.GetHashCode().ToString();
                customCreators.Remove(key);
            }
        }

        public virtual void RemoveToolboxItem(ToolboxItem toolComponentClass)
        {
        }

        public virtual void RemoveToolboxItem(ToolboxItem componentClass, string category)
        {
        }

        public virtual bool SetCursor()
        {
            if (this.currentSelection != null)
            {
                Cursor.Current = Cursors.Cross;
                return true;
            }

            return false;
        }

        public virtual void SetSelectedToolboxItem(ToolboxItem selectedToolClass)
        {
            if (selectedToolClass == null)
            {
                listBox.SelectedIndex = 0;
                OnListBoxClick(null, EventArgs.Empty);
            }
        }

        public void AddType(Type t)
        {
            listBox.Items.Add(new wxdActivityToolItem(t.AssemblyQualifiedName));
        }

        public Attribute[] GetEnabledAttributes()
        {
            return null;
        }

        public void SetEnabledAttributes(Attribute[] attrs)
        {
        }

        public void SelectedToolboxItemUsed()
        {
            SetSelectedToolboxItem(null);
        }


        //Gets the toolbox item associated with a component type
        internal static ToolboxItem GetToolboxItem(Type toolType)
        {
            if (toolType == null)
                throw new ArgumentNullException("toolType");

            ToolboxItem item = null;
            if ((toolType.IsPublic || toolType.IsNestedPublic) && typeof(IComponent).IsAssignableFrom(toolType) && !toolType.IsAbstract)
            {
                ToolboxItemAttribute toolboxItemAttribute = (ToolboxItemAttribute)TypeDescriptor.GetAttributes(toolType)[typeof(ToolboxItemAttribute)];
                if (toolboxItemAttribute != null && !toolboxItemAttribute.IsDefaultAttribute())
                {
                    Type itemType = toolboxItemAttribute.ToolboxItemType;
                    if (itemType != null)
                    {
                        // First, try to find a constructor with Type as a parameter.  If that
                        // fails, try the default constructor.
                        ConstructorInfo ctor = itemType.GetConstructor(new Type[] { typeof(Type) });
                        if (ctor != null)
                        {
                            item = (ToolboxItem)ctor.Invoke(new object[] { toolType });
                        }
                        else
                        {
                            ctor = itemType.GetConstructor(new Type[0]);
                            if (ctor != null)
                            {
                                item = (ToolboxItem)ctor.Invoke(new object[0]);
                                item.Initialize(toolType);
                            }
                        }
                    }
                }
                else if (!toolboxItemAttribute.Equals(ToolboxItemAttribute.None))
                {
                    item = new ToolboxItem(toolType);
                }
            }
            else if (typeof(ToolboxItem).IsAssignableFrom(toolType))
            {
                // if the type *is* a toolboxitem, just create it..
                //
                try
                {
                    item = (ToolboxItem)Activator.CreateInstance(toolType, true);
                }
                catch
                {
                }
            }

            return item;
        }


        private void AddToolboxEntries(ListBox lb)
        {
            if (activityToolItemFile == "")
            { return; }
            System.IO.FileStream selfTools = new FileStream(activityToolItemFile, System.IO.FileMode.Open);

            int len = (int)selfTools.Length;
            byte[] bytes = new byte[len];
            selfTools.Read(bytes, 0, len);

            string entries = Encoding.Default.GetString(bytes);

            int start = 0, end = 0;
            string entry;
            while (end < entries.Length)
            {
                end = entries.IndexOf('\r', start);
                if (end == -1)
                { end = entries.Length; }

                entry = entries.Substring(start, (end - start));
                if (entry.Length != 0 && !entry.StartsWith(";"))
                { lb.Items.Add(new wxdActivityToolItem(entry)); }


                start = end + 2;
            }
            selfTools.Close();
        }

        private void OnDrawItem(object sender, DrawItemEventArgs e)
        {
            Graphics g = e.Graphics;
            ListBox listBox = (ListBox)sender;
            object objItem = listBox.Items[e.Index];
            wxdActivityToolItem item = null;
            Bitmap bitmap = null;
            string text = null;

            if (objItem is string)
            {
                bitmap = null;
                text = (string)objItem;
            }
            else
            {
                try
                {
                    item = (wxdActivityToolItem)objItem;
                    bitmap = (Bitmap)item.Glyph;
                    text = item.Name;
                }
                catch
                {

                }
            }

            bool selected = false;
            bool disabled = false;

            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                selected = true;

            if ((int)(e.State & (DrawItemState.Disabled | DrawItemState.Grayed | DrawItemState.Inactive)) != 0)
                disabled = true;

            StringFormat format = new StringFormat();
            format.HotkeyPrefix = HotkeyPrefix.Show;

            int x = e.Bounds.X + 4;
            x += 20;

            if (selected)
            {
                Rectangle r = e.Bounds;
                r.Width--; r.Height--;
                g.DrawRectangle(SystemPens.ActiveCaption, r);
            }
            else
            {
                g.FillRectangle(SystemBrushes.Menu, e.Bounds);
                using (Brush border = new SolidBrush(Color.FromArgb(Math.Min(SystemColors.Menu.R + 15, 255), Math.Min(SystemColors.Menu.G + 15, 255), Math.Min(SystemColors.Menu.B + 15, 255))))
                    g.FillRectangle(border, new Rectangle(e.Bounds.X, e.Bounds.Y, 20, e.Bounds.Height));
            }

            if (bitmap != null)
                g.DrawImage(bitmap, e.Bounds.X + 2, e.Bounds.Y + 2, bitmap.Width, bitmap.Height);

            Brush textBrush = (disabled) ? new SolidBrush(Color.FromArgb(120, SystemColors.MenuText)) : SystemBrushes.FromSystemColor(SystemColors.MenuText);
            g.DrawString(text, Font, textBrush, x, e.Bounds.Y + 2, format);
            if (disabled)
                textBrush.Dispose();
            format.Dispose();
        }


        private void OnListBoxMouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && this.listBox.SelectedItem != null)
            {
                wxdActivityToolItem selectedItem = listBox.SelectedItem as wxdActivityToolItem;

                if (selectedItem == null || selectedItem.ComponentClass == null)
                    return;

                ToolboxItem toolboxItem = wxdActivityTool.GetToolboxItem(selectedItem.ComponentClass);
                IDataObject dataObject = this.SerializeToolboxItem(toolboxItem) as IDataObject;
                DragDropEffects effects = DoDragDrop(dataObject, DragDropEffects.Copy | DragDropEffects.Move);
            }
        }

        private void OnListBoxClick(object sender, EventArgs eevent)
        {
            wxdActivityToolItem toolboxItem = listBox.SelectedItem as wxdActivityToolItem;
            if (toolboxItem != null)
            {
                this.currentSelection = toolboxItem.ComponentClass;
            }
            else if (this.currentSelection != null)
            {
                int index = this.listBox.Items.IndexOf(this.currentSelection);
                if (index >= 0)
                    this.listBox.SelectedIndex = index;
            }
        }
    }
	
}

⌨️ 快捷键说明

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