Пример #1
0
        public void ToString_StateUnderTest_ExpectedBehavior()
        {
            var type          = typeof(Bitmap);
            var unitUnderTest = new ToolboxItem(type);
            var result        = unitUnderTest.ToString();

            Assert.Equal(type.Name, result);
        }
Пример #2
0
        public void ToolBoxItem_Constructor()
        {
            var         type      = typeof(Bitmap);
            ToolboxItem underTest = new ToolboxItem(type);

            Assert.Equal("System.Drawing.Bitmap", underTest.TypeName);
            Assert.Equal("Bitmap", underTest.DisplayName);
            Assert.Equal("Bitmap", underTest.ToString());
            Assert.False(underTest.Locked);
            Assert.True(underTest.GetType().IsSerializable);
        }
Пример #3
0
        private Color RowBackColorSel = Color.FromArgb(106, 197, 242); //选中项目颜色
        private void Toolbox_DrawItem(object sender, DrawItemEventArgs e)
        {
            Brush myBrush = Brushes.Black;

            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                myBrush = new SolidBrush(RowBackColorSel);
            }
            else if (e.Index % 2 == 0)
            {
                myBrush = new SolidBrush(RowBackColorAlt);
            }
            else
            {
                myBrush = new SolidBrush(Color.White);
            }
            e.Graphics.FillRectangle(myBrush, e.Bounds);
            e.DrawFocusRectangle();//焦点框
            ToolboxItem tbi = _ctrlToolBox.Items[e.Index] as ToolboxItem;
            //绘制图表
            //Image image = Image.FromFile(@"..\..\ico\聊天界面头像2.png");
            Graphics  g         = e.Graphics;
            Rectangle bounds    = e.Bounds;
            Rectangle imageRect = new Rectangle(bounds.X, bounds.Y, bounds.Height, bounds.Width);
            Rectangle textRect  = new Rectangle(imageRect.Right, bounds.X,
                                                bounds.Width - imageRect.Right, bounds.Height);

            if (tbi.Bitmap != null)
            {
                Image image = (Image)tbi.Bitmap;
                g.DrawImage(image, imageRect, 0, 0, image.Width, image.Height, GraphicsUnit.Pixel);
            }

            //文本
            StringFormat strFormat = new StringFormat();

            strFormat.LineAlignment = StringAlignment.Center;
            e.Graphics.DrawString(tbi.ToString(), e.Font, new SolidBrush(e.ForeColor), textRect, strFormat);
        }
Пример #4
0
        public IComponent[] CreateTool(ToolboxItem tool, Control parent, int x, int y, int width, int height, bool hasLocation, bool hasSize, ToolboxSnapDragDropEventArgs e)
        {
            // Services we will need
            //
            IToolboxService   toolboxSvc = (IToolboxService)GetService(typeof(IToolboxService));
            ISelectionService selSvc     = (ISelectionService)GetService(typeof(ISelectionService));
            IDesignerHost     host       = (IDesignerHost)GetService(typeof(IDesignerHost));

            IComponent[] comps = Array.Empty <IComponent>();

            Cursor oldCursor = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;
            DesignerTransaction trans = null;

            try
            {
                try
                {
                    if (host != null)
                    {
                        trans = host.CreateTransaction(string.Format(SR.DesignerBatchCreateTool, tool.ToString()));
                    }
                }
                catch (CheckoutException cxe)
                {
                    if (cxe == CheckoutException.Canceled)
                    {
                        return(comps);
                    }

                    throw;
                }

                try
                {
                    try
                    {
                        // First check if we are currently in localization mode (i.e., language is non-default).
                        // If so, we should not permit addition of new components. This is an intentional
                        // change from Everett - see VSWhidbey #292249.
                        if (host != null && CurrentlyLocalizing(host.RootComponent))
                        {
                            IUIService uiService = (IUIService)GetService(typeof(IUIService));
                            if (uiService != null)
                            {
                                uiService.ShowMessage(SR.LocalizingCannotAdd);
                            }

                            comps = Array.Empty <IComponent>();
                            return(comps);
                        }

                        // Create a dictionary of default values that the designer can
                        // use to initialize a control with.
                        Hashtable defaultValues = new Hashtable();
                        if (parent != null)
                        {
                            defaultValues["Parent"] = parent;
                        }

                        // adjust the location if we are in a mirrored parent. That is because the origin
                        // will then be in the upper right rather than upper left.
                        if (parent != null && parent.IsMirrored)
                        {
                            x += width;
                        }

                        if (hasLocation)
                        {
                            defaultValues["Location"] = new Point(x, y);
                        }
                        if (hasSize)
                        {
                            defaultValues["Size"] = new Size(width, height);
                        }
                        //store off extra behavior drag/drop information
                        if (e != null)
                        {
                            defaultValues["ToolboxSnapDragDropEventArgs"] = e;
                        }

                        comps = tool.CreateComponents(host, defaultValues);
                    }
                    catch (CheckoutException checkoutEx)
                    {
                        if (checkoutEx == CheckoutException.Canceled)
                        {
                            comps = Array.Empty <IComponent>();
                        }
                        else
                        {
                            throw;
                        }
                    }
                    catch (ArgumentException argumentEx)
                    {
                        IUIService uiService = (IUIService)GetService(typeof(IUIService));
                        if (uiService != null)
                        {
                            uiService.ShowError(argumentEx);
                        }
                    }
                    catch (Exception ex)
                    {
                        IUIService uiService = (IUIService)GetService(typeof(IUIService));

                        string exceptionMessage = string.Empty;
                        if (ex.InnerException != null)
                        {
                            exceptionMessage = ex.InnerException.ToString();
                        }

                        if (string.IsNullOrEmpty(exceptionMessage))
                        {
                            exceptionMessage = ex.ToString();
                        }

                        if (ex is InvalidOperationException)
                        {
                            exceptionMessage = ex.Message;
                        }

                        if (uiService != null)
                        {
                            uiService.ShowError(ex, string.Format(SR.FailedToCreateComponent, tool.DisplayName, exceptionMessage));
                        }
                        else
                        {
                            throw;
                        }
                    }

                    if (comps == null)
                    {
                        comps = Array.Empty <IComponent>();
                    }
                }
                finally
                {
                    if (toolboxSvc != null && tool.Equals(toolboxSvc.GetSelectedToolboxItem(host)))
                    {
                        toolboxSvc.SelectedToolboxItemUsed();
                    }
                }
            }
            finally
            {
                if (trans != null)
                {
                    trans.Commit();
                }

                Cursor.Current = oldCursor;
            }

            // Finally, select the newly created components.
            //
            if (selSvc != null && comps.Length > 0)
            {
                if (host != null)
                {
                    host.Activate();
                }

                ArrayList selectComps = new ArrayList(comps);

                for (int i = 0; i < comps.Length; i++)
                {
                    if (!TypeDescriptor.GetAttributes(comps[i]).Contains(DesignTimeVisibleAttribute.Yes))
                    {
                        selectComps.Remove(comps[i]);
                    }
                }

                selSvc.SetSelectedComponents(selectComps.ToArray(), SelectionTypes.Replace);
            }

            codemarkers.CodeMarker((int)CodeMarkerEvent.perfFXDesignCreateComponentEnd);
            return(comps);
        }