public void ToolBoxItem_Equals() { var type = typeof(Bitmap); ToolboxItem underTest = new ToolboxItem(type); ToolboxItem underTest2 = new ToolboxItem(type); ToolboxItem underTest3 = new ToolboxItem(typeof(string)); Assert.True(underTest.Equals(underTest2)); Assert.False(underTest.Equals(underTest3)); }
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); }