public void GetImage_NullComponent_ReturnsNull() { var attribute = new ToolboxBitmapAttribute((string)null); Assert.Null(attribute.GetImage((object)null)); Assert.Null(attribute.GetImage((object)null, true)); }
public void GetImage_Default_ReturnsExpected() { ToolboxBitmapAttribute attribute = ToolboxBitmapAttribute.Default; using (Image image = attribute.GetImage(typeof(ToolboxBitmapAttributeTests), "bitmap_173x183_indexed_8bit", large: true)) { Assert.Equal(new Size(32, 32), image.Size); } using (Image image = attribute.GetImage(typeof(ToolboxBitmapAttributeTests), "bitmap_173x183_indexed_8bit", large: false)) { Assert.Equal(new Size(173, 183), image.Size); } }
public void GetImage_Component_ReturnsExpected() { ToolboxBitmapAttribute attribute = new ToolboxBitmapAttribute((string)null); using (Image smallImage = attribute.GetImage(new bitmap_173x183_indexed_8bit(), large: false)) { Assert.Equal(new Size(173, 183), smallImage.Size); using (Image largeImage = attribute.GetImage(new bitmap_173x183_indexed_8bit(), large: true)) { Assert.Equal(new Size(32, 32), largeImage.Size); } } }
public void GetImage_TypeFileNameBool_ReturnsExpected(string fileName, int width, int height) { var attribute = new ToolboxBitmapAttribute((string)null); using (Image image = attribute.GetImage(typeof(ToolboxBitmapAttributeTests), fileName, large: true)) { Assert.Equal(new Size(32, 32), image.Size); } using (Image image = attribute.GetImage(typeof(ToolboxBitmapAttributeTests), fileName, large: false)) { Assert.Equal(new Size(width, height), image.Size); } }
public static Image GetToolboxImage(Type activityType) { if (activityType == null) { throw new ArgumentNullException("activityType"); } Image toolBoxImage = null; if (activityType != null) { object[] attribs = activityType.GetCustomAttributes(typeof(ToolboxBitmapAttribute), false); if (attribs != null && attribs.GetLength(0) == 0) { attribs = activityType.GetCustomAttributes(typeof(ToolboxBitmapAttribute), true); } ToolboxBitmapAttribute toolboxBitmapAttribute = (attribs != null && attribs.GetLength(0) > 0) ? attribs[0] as ToolboxBitmapAttribute : null; if (toolboxBitmapAttribute != null) { toolBoxImage = toolboxBitmapAttribute.GetImage(activityType); } } return(toolBoxImage); }
// Methods public ListBoxItem(DataGridViewColumn column, ExtDataGridColumnCollectionDialog owner, ComponentDesigner compDesigner) { this.column = column; this.owner = owner; this.compDesigner = compDesigner; if (this.compDesigner != null) { this.compDesigner.Initialize(column); TypeDescriptor.CreateAssociation(this.column, this.compDesigner); } ToolboxBitmapAttribute attribute = TypeDescriptor.GetAttributes(column)[ExtDataGridColumnCollectionDialog.toolboxBitmapAttributeType] as ToolboxBitmapAttribute; if (attribute != null) { this.toolboxBitmap = attribute.GetImage(column, false); } else { //this.toolboxBitmap = this.owner.SelectedColumnsItemBitmap; } DataGridViewColumnDesigner designer = compDesigner as DataGridViewColumnDesigner; if (designer != null) { //designer.LiveDataGridView = this.owner.liveDataGridView; } }
private void SetSelectedChart() { if (_component.ChartControl != null) { lblDestination.Text = ((Control)_component.ChartControl).Name; try { Image resultImage = null; AttributeCollection attrCol = TypeDescriptor.GetAttributes(_component.CurrentAdapter.GetType()); ToolboxBitmapAttribute imageAttr = (ToolboxBitmapAttribute)attrCol[typeof(ToolboxBitmapAttribute)]; if (imageAttr != null) { resultImage = imageAttr.GetImage(_component.CurrentAdapter.GetType(), false);//false - 16x16, true - 32x32 int index = 0; imageListCharts.Images.Add(resultImage); index = imageListCharts.Images.Count; lblDestination.ImageIndex = index; } } catch { } InitSeriesList(); } }
protected virtual void CreateDragFeedbackImages(IList <Activity> draggedActivities) { Bitmap draggedImage = null; if (draggedActivities.Count > 0) { Bitmap image = null; String description = String.Empty; if (draggedActivities.Count > 1) { image = DR.GetImage(DR.Activities) as Bitmap; description = DR.GetString(DR.ActivitiesDesc); } else { ToolboxBitmapAttribute toolboxBitmapAttribute = (ToolboxBitmapAttribute)TypeDescriptor.GetAttributes(draggedActivities[0].GetType())[typeof(ToolboxBitmapAttribute)]; image = toolboxBitmapAttribute.GetImage(draggedActivities[0].GetType()) as Bitmap; description = draggedActivities[0].GetType().Name; } if (image != null && description.Length > 0) { //Start creating a bitmap WorkflowView parentView = ParentView; Rectangle imageRectangle = (image != null) ? new Rectangle(Point.Empty, image.Size) : Rectangle.Empty; Rectangle descriptionRectangle = (description.Length > 0) ? new Rectangle(Point.Empty, new Size(AmbientTheme.DragImageTextSize.Width, parentView.Font.Height + 2)) : Rectangle.Empty; if (!imageRectangle.IsEmpty) { descriptionRectangle.Offset(imageRectangle.Width + AmbientTheme.DragImageMargins.Width, 0); } Size draggedImageSize = parentView.LogicalSizeToClient(new Size(imageRectangle.Width + descriptionRectangle.Width, Math.Max(imageRectangle.Height, descriptionRectangle.Height))); draggedImage = new Bitmap(draggedImageSize.Width, draggedImageSize.Height, PixelFormat.Format32bppArgb); using (Graphics draggedImageGraphics = Graphics.FromImage(draggedImage)) using (Brush backgroundBrush = new SolidBrush(Color.FromArgb(0, 255, 0, 255))) { draggedImageGraphics.ScaleTransform(ScaleZoomFactor, ScaleZoomFactor); draggedImageGraphics.FillRectangle(backgroundBrush, new Rectangle(0, 0, draggedImage.Width, draggedImage.Height)); if (image != null) { draggedImageGraphics.DrawImage(image, new Rectangle(Point.Empty, image.Size)); } if (description.Length > 0) { StringFormat stringFormat = new StringFormat(); stringFormat.Alignment = StringAlignment.Near; stringFormat.Trimming = StringTrimming.EllipsisCharacter; stringFormat.LineAlignment = StringAlignment.Center; draggedImageGraphics.DrawString(description, parentView.Font, SystemBrushes.WindowText, descriptionRectangle, stringFormat); } } } } this.dragImage = draggedImage; }
protected virtual void CreateDragFeedbackImages(IList <Activity> draggedActivities) { Bitmap image = null; if (draggedActivities.Count > 0) { Bitmap bitmap2 = null; string s = string.Empty; if (draggedActivities.Count > 1) { bitmap2 = DR.GetImage("Activities") as Bitmap; s = DR.GetString("ActivitiesDesc", new object[0]); } else { ToolboxBitmapAttribute attribute = (ToolboxBitmapAttribute)TypeDescriptor.GetAttributes(draggedActivities[0].GetType())[typeof(ToolboxBitmapAttribute)]; bitmap2 = attribute.GetImage(draggedActivities[0].GetType()) as Bitmap; s = draggedActivities[0].GetType().Name; } if ((bitmap2 != null) && (s.Length > 0)) { WorkflowView parentView = base.ParentView; Rectangle rectangle = (bitmap2 != null) ? new Rectangle(Point.Empty, bitmap2.Size) : Rectangle.Empty; Rectangle layoutRectangle = (s.Length > 0) ? new Rectangle(Point.Empty, new Size(AmbientTheme.DragImageTextSize.Width, parentView.Font.Height + 2)) : Rectangle.Empty; if (!rectangle.IsEmpty) { layoutRectangle.Offset(rectangle.Width + AmbientTheme.DragImageMargins.Width, 0); } Size size = parentView.LogicalSizeToClient(new Size(rectangle.Width + layoutRectangle.Width, Math.Max(rectangle.Height, layoutRectangle.Height))); image = new Bitmap(size.Width, size.Height, PixelFormat.Format32bppArgb); using (Graphics graphics = Graphics.FromImage(image)) { using (Brush brush = new SolidBrush(Color.FromArgb(0, 0xff, 0, 0xff))) { graphics.ScaleTransform(this.ScaleZoomFactor, this.ScaleZoomFactor); graphics.FillRectangle(brush, new Rectangle(0, 0, image.Width, image.Height)); if (bitmap2 != null) { graphics.DrawImage(bitmap2, new Rectangle(Point.Empty, bitmap2.Size)); } if (s.Length > 0) { StringFormat format = new StringFormat { Alignment = StringAlignment.Near, Trimming = StringTrimming.EllipsisCharacter, LineAlignment = StringAlignment.Center }; graphics.DrawString(s, parentView.Font, SystemBrushes.WindowText, layoutRectangle, format); } } } } } this.dragImage = image; }
private void InitToolBox() { //- Add the toolboxItems to the future toolbox //- the pointer //ToolboxItem toolPointer = new System.Drawing.Design.ToolboxItem(); //toolPointer.DisplayName = $"<Pointer>"; //toolPointer.Bitmap = new System.Drawing.Bitmap(16, 16); //_ctrlToolBox.Items.Add(toolPointer); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(Button))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(CheckBox))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(ComboBox))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(ContextMenuStrip))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(DataGridView))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(GroupBox))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(ImageList))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(Label))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(LinkLabel))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(ListView))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(OpenFileDialog))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(Panel))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(PictureBox))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(ProgressBar))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(MenuStrip))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(RadioButton))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(StatusBar))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(TabControl))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(TextBox))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(Timer))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(ToolBar))); //_ctrlToolBox.Items.Add(new ToolboxItem(typeof(TreeView))); var pointer = new ToolboxItem(); pointer.DisplayName = "<Pointer>"; pointer.Bitmap = new Bitmap(16, 16); _ctrlToolBox.Items.Add(pointer); foreach (Type type in _windowsFormsToolTypes) { ToolboxItem tbi = new ToolboxItem(type); ToolboxBitmapAttribute tba = TypeDescriptor.GetAttributes(type)[typeof(ToolboxBitmapAttribute)] as ToolboxBitmapAttribute; if (tba != null) { tbi.Bitmap = (Bitmap)tba.GetImage(type); } _ctrlToolBox.Items.Add(tbi); } //- init the (UDesigner)pDesignerCore _idesigner.CtrlToolbox = _ctrlToolBox; _ctrlToolBox.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.Toolbox_DrawItem); _ctrlToolBox.Invalidate(); }
private Image GetControlIcon(object control) { ToolboxBitmapAttribute attribute = TypeDescriptor.GetAttributes(control)[toolboxBitmapAttributeType] as ToolboxBitmapAttribute; if (attribute != null) { //img里取到的即是控件textBox1在工具箱中的图标 return(attribute.GetImage(control, true)); } return(null); }
private Image GetChartImage(Type chartType) { AttributeCollection attrCol = TypeDescriptor.GetAttributes(chartType); ToolboxBitmapAttribute imageAttr = (ToolboxBitmapAttribute)attrCol[typeof(ToolboxBitmapAttribute)]; if (imageAttr != null) { return(imageAttr.GetImage(chartType.GetType(), false));//false - 16x16, true - 32x32 } return(new Bitmap(16, 16)); }
static Toolbox() { foreach (KeyValuePair <string, Type[]> keyValuePair in Toolbox.toolboxControls) { ToolboxItem value = new ToolboxItem(keyValuePair.Value[1]); Toolbox.toolboxItemDictionary.Add(keyValuePair.Key, value); ToolboxBitmapAttribute toolboxBitmapAttribute = TypeDescriptor.GetAttributes(keyValuePair.Value[0])[typeof(ToolboxBitmapAttribute)] as ToolboxBitmapAttribute; Bitmap bitmap = (Bitmap)toolboxBitmapAttribute.GetImage(keyValuePair.Value[0]); Icon icon = Icon.FromHandle(bitmap.GetHicon()); Toolbox.iconLibrary.Icons.Add(keyValuePair.Key, icon); } }
private void InitializePanelControls() { this._selectLabel.Text = System.Design.SR.GetString("CreateDataSource_SelectType"); this._idLabel.Text = System.Design.SR.GetString("CreateDataSource_ID"); base.OKButton.Enabled = false; this.Text = System.Design.SR.GetString("CreateDataSource_Title"); this._descriptionBox.Text = System.Design.SR.GetString("CreateDataSource_SelectTypeDesc"); base.AccessibleDescription = System.Design.SR.GetString("CreateDataSource_Description"); base.CaptionLabel.Text = System.Design.SR.GetString("CreateDataSource_Caption"); this.UpdateFonts(); ISite site = this.GetSite(); if (site != null) { IComponentDiscoveryService service = (IComponentDiscoveryService)site.GetService(typeof(IComponentDiscoveryService)); IDesignerHost designerHost = (IDesignerHost)site.GetService(typeof(IDesignerHost)); if (service != null) { ICollection componentTypes = service.GetComponentTypes(designerHost, this._dataSourceType); if (componentTypes != null) { ImageList list = new ImageList { ColorDepth = ColorDepth.Depth32Bit }; System.Type[] array = new System.Type[componentTypes.Count]; componentTypes.CopyTo(array, 0); foreach (System.Type type in array) { System.ComponentModel.AttributeCollection attributes = TypeDescriptor.GetAttributes(type); Bitmap image = null; if (attributes != null) { ToolboxBitmapAttribute attribute = attributes[typeof(ToolboxBitmapAttribute)] as ToolboxBitmapAttribute; if ((attribute != null) && !attribute.Equals(ToolboxBitmapAttribute.Default)) { image = attribute.GetImage(type, true) as Bitmap; } } if (image == null) { image = new Bitmap(base.GetType(), "CustomDataSource.bmp"); } list.ImageSize = new Size(0x20, 0x20); list.Images.Add(type.FullName, image); this._dataSourceTypesListView.Items.Add(new DataSourceListViewItem(type)); } this._dataSourceTypesListView.Sort(); this._dataSourceTypesListView.LargeImageList = list; } } } }
// <snippet4> private Image GetImageOfCustomControl(Control userControl) { Image controlImage = null; AttributeCollection attrCol = TypeDescriptor.GetAttributes(userControl); ToolboxBitmapAttribute imageAttr = (ToolboxBitmapAttribute) attrCol[typeof(ToolboxBitmapAttribute)]; if (imageAttr != null) { controlImage = imageAttr.GetImage(userControl); } return(controlImage); }
// Fill our ListBoxes with the appropriate ToolboxItems. private void FillToolbox() { foreach (ListBarGroup tab in listBar1.Groups) { tab.Items.Add(pointerItem); } foreach (List <ToolboxItem> t in listAll) { t.Add(pointer); } foreach (Type type in windowsFormsToolTypes) { ToolboxItem tbi = new ToolboxItem(type); ToolboxBitmapAttribute tba = TypeDescriptor.GetAttributes(type)[typeof(ToolboxBitmapAttribute)] as ToolboxBitmapAttribute; if (tba != null) { tbi.Bitmap = (Bitmap)tba.GetImage(type); } listWindowsForms_ti.Add(tbi); AddBarItem(listWindowsForms, tbi); } foreach (Type type in componentsToolTypes) { ToolboxItem tbi = new ToolboxItem(type); ToolboxBitmapAttribute tba = TypeDescriptor.GetAttributes(type)[typeof(ToolboxBitmapAttribute)] as ToolboxBitmapAttribute; if (tba != null) { tbi.Bitmap = (Bitmap)tba.GetImage(type); } listComponents_ti.Add(tbi); AddBarItem(listComponents, tbi); } foreach (Type type in dataToolTypes) { ToolboxItem tbi = new ToolboxItem(type); ToolboxBitmapAttribute tba = TypeDescriptor.GetAttributes(type)[typeof(ToolboxBitmapAttribute)] as ToolboxBitmapAttribute; if (tba != null) { tbi.Bitmap = (Bitmap)tba.GetImage(type); } listData_ti.Add(tbi); AddBarItem(listData, tbi); } }
public void Ctor_FileName(string fileName, Size size) { var attribute = new ToolboxBitmapAttribute(fileName); using (Image image = attribute.GetImage(null)) { if (size == Size.Empty) { Assert.Throws <ArgumentException>(null, () => image.Size); } else { Assert.Equal(size, image.Size); } } }
public void Ctor_Type_String(Type type, string fileName, int width, int height) { var attribute = new ToolboxBitmapAttribute(type, fileName); using (Image image = attribute.GetImage(type, fileName, false)) { if (width == -1 && height == -1) { Assert.Throws <ArgumentException>(null, () => image.Size); } else { Assert.Equal(new Size(width, height), image.Size); } } }
public void Ctor_Type(Type type, int width, int height) { var attribute = new ToolboxBitmapAttribute(type); using (Image image = attribute.GetImage(type)) { if (width == -1 && height == -1) { AssertDefaultSize(image); } else { Assert.Equal(new Size(width, height), image.Size); } } }
public void Ctor_FileName(string fileName, Size size) { var attribute = new ToolboxBitmapAttribute(fileName); using (Image image = attribute.GetImage(null)) { if (size == Size.Empty) { AssertDefaultSize(image); } else { Assert.Equal(size, image.Size); } } }
// Fill our ListBoxes with the appropriate ToolboxItems. private void FillToolbox() { foreach (TabPage tab in tabControl.TabPages) { ListBox list = tab.Controls[0] as ListBox; list.Items.Add(pointer); } foreach (Type type in etoFormsToolTypes) { ToolboxItem tbi = new ToolboxItem(type); ToolboxBitmapAttribute tba = TypeDescriptor.GetAttributes(type)[typeof(ToolboxBitmapAttribute)] as ToolboxBitmapAttribute; if (tba != null) { tbi.Bitmap = (Bitmap)tba.GetImage(type); } listEtoForms.Items.Add(tbi); } foreach (Type type in componentsToolTypes) { ToolboxItem tbi = new ToolboxItem(type); ToolboxBitmapAttribute tba = TypeDescriptor.GetAttributes(type)[typeof(ToolboxBitmapAttribute)] as ToolboxBitmapAttribute; if (tba != null) { tbi.Bitmap = (Bitmap)tba.GetImage(type); } listComponents.Items.Add(tbi); } foreach (Type type in dataToolTypes) { ToolboxItem tbi = new ToolboxItem(type); ToolboxBitmapAttribute tba = TypeDescriptor.GetAttributes(type)[typeof(ToolboxBitmapAttribute)] as ToolboxBitmapAttribute; if (tba != null) { tbi.Bitmap = (Bitmap)tba.GetImage(type); } listData.Items.Add(tbi); } }
/// <summary> /// paint the listbox items /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void ItemsListBox_DrawItem(object sender, DrawItemEventArgs e) { ListBox listbox = sender as ListBox; if (e.Index == -1) { return; } Rectangle rect = new Rectangle(e.Bounds.X, e.Bounds.Y, Width, e.Bounds.Height); Brush b = brush; // If this item is the currently selected item, draw it with a highlight. if (listbox.SelectedIndex == e.Index) { b = Brushes.Moccasin; } e.Graphics.FillRectangle(b, rect); Control control = listbox.Items[e.Index] as Control; Control controlForBitmap = control is DotNetComponentWrapper ? ((DotNetComponentWrapper)control).WrappedControl : control; // get the bitmap ToolboxBitmapAttribute tba = TypeDescriptor.GetAttributes(controlForBitmap)[typeof(ToolboxBitmapAttribute)] as ToolboxBitmapAttribute; Bitmap bitmap = (Bitmap)tba.GetImage(controlForBitmap); Rectangle bitmapBounds = new Rectangle(rect.Location.X + 20, rect.Location.Y + 2, 16, 16); Rectangle stringBounds = new Rectangle(rect.Location.X + bitmapBounds.Width + 25, rect.Location.Y, 145, rect.Height); StringFormat format = new StringFormat(); format.LineAlignment = StringAlignment.Center; format.Alignment = StringAlignment.Near; format.FormatFlags = StringFormatFlags.NoWrap; format.Trimming = StringTrimming.EllipsisCharacter; e.Graphics.DrawImage(bitmap, bitmapBounds); e.Graphics.DrawString((string)((ControlDesignerInfo)control.Tag).Properties[Constants.WinPropName].Value, font, Brushes.Black, stringBounds, format); }
// FIXME - Should we be returning empty bitmap, or null? public virtual void Initialize(Type type) { CheckUnlocked(); if (type == null) { return; } AssemblyName = type.Assembly.GetName(); DisplayName = type.Name; TypeName = type.FullName; // seems to be a right place to create the bitmap System.DrawingCore.Image image = null; foreach (object attribute in type.GetCustomAttributes(true)) { ToolboxBitmapAttribute tba = attribute as ToolboxBitmapAttribute; if (tba != null) { image = tba.GetImage(type); break; } } //fallback: check for image even if not attribute if (image == null) { image = ToolboxBitmapAttribute.GetImageFromResource(type, null, false); } if (image != null) { Bitmap = (image as Bitmap); if (Bitmap == null) { Bitmap = new Bitmap(image); } } Filter = type.GetCustomAttributes(typeof(ToolboxItemFilterAttribute), true); }
public static Image GetToolboxImage(Type activityType) { if (activityType == null) { throw new ArgumentNullException("activityType"); } Image image = null; if (activityType != null) { object[] customAttributes = activityType.GetCustomAttributes(typeof(ToolboxBitmapAttribute), false); if ((customAttributes != null) && (customAttributes.GetLength(0) == 0)) { customAttributes = activityType.GetCustomAttributes(typeof(ToolboxBitmapAttribute), true); } ToolboxBitmapAttribute attribute = ((customAttributes != null) && (customAttributes.GetLength(0) > 0)) ? (customAttributes[0] as ToolboxBitmapAttribute) : null; if (attribute != null) { image = attribute.GetImage(activityType); } } return(image); }
public Bitmap GetIcon(ToolComponent component) { Assembly asm = component.LoadAssembly(); Type type = asm.GetType(component.FullName); Bitmap b = null; if (type != null) { object[] attributes = type.GetCustomAttributes(false); foreach (object attr in attributes) { if (attr is ToolboxBitmapAttribute) { ToolboxBitmapAttribute toolboxBitmapAttribute = (ToolboxBitmapAttribute)attr; b = new Bitmap(toolboxBitmapAttribute.GetImage(type)); b.MakeTransparent(); break; } } } if (b == null) { try { Stream imageStream = asm.GetManifestResourceStream(component.FullName + ".bmp"); if (imageStream != null) { b = new Bitmap(Image.FromStream(imageStream)); b.MakeTransparent(); } } catch (Exception e) { ICSharpCode.Core.LoggingService.Warn("ComponentLibraryLoader.GetIcon: " + e.Message); } } // TODO: Maybe default icon needed ??!?! return(b); }
/// <include file='doc\ToolboxItem.uex' path='docs/doc[@for="ToolboxItem.Initialize"]/*' /> /// <devdoc> /// Initializes a toolbox item with a given type. A locked toolbox item cannot be initialized. /// </devdoc> public virtual void Initialize(Type type) { CheckUnlocked(); if (type != null) { typeName = type.FullName; assemblyName = type.Assembly.GetName(true); if (type.Assembly.GlobalAssemblyCache) { assemblyName.CodeBase = null; } displayName = type.Name; ToolboxBitmapAttribute attr = (ToolboxBitmapAttribute)TypeDescriptor.GetAttributes(type)[typeof(ToolboxBitmapAttribute)]; if (attr != null) { itemBitmap = attr.GetImage(type, false) as Bitmap; // make sure this thing is 16x16 if (itemBitmap != null && (itemBitmap.Width != 16 || itemBitmap.Height != 16)) { itemBitmap = new Bitmap(itemBitmap, new Size(16, 16)); } } ArrayList array = new ArrayList(); foreach (Attribute a in TypeDescriptor.GetAttributes(type)) { if (a is ToolboxItemFilterAttribute) { array.Add(a); } } filter = new ToolboxItemFilterAttribute[array.Count]; array.CopyTo(filter); } }
void AddComponentsToList(Assembly assembly, string loadPath) { if (assembly != null) { Hashtable images = new Hashtable(); ImageList il = new ImageList(); // try to load res icon string[] imgNames = assembly.GetManifestResourceNames(); foreach (string im in imgNames) { try { Bitmap b = new Bitmap(Image.FromStream(assembly.GetManifestResourceStream(im))); b.MakeTransparent(); images[im] = il.Images.Count; il.Images.Add(b); } catch {} } try { componentListView.SmallImageList = il; foreach (Type t in assembly.GetExportedTypes()) { if (!t.IsAbstract) { if (t.IsDefined(typeof(ToolboxItemFilterAttribute), true) || t.IsDefined(typeof(ToolboxItemAttribute), true) || typeof(System.ComponentModel.IComponent).IsAssignableFrom(t)) { object[] attributes = t.GetCustomAttributes(false); object[] filterAttrs = t.GetCustomAttributes(typeof(DesignTimeVisibleAttribute), true); foreach (DesignTimeVisibleAttribute visibleAttr in filterAttrs) { if (!visibleAttr.Visible) { goto skip; } } if (images[t.FullName + ".bmp"] == null) { if (t.IsDefined(typeof(ToolboxBitmapAttribute), false)) { foreach (object attr in attributes) { if (attr is ToolboxBitmapAttribute) { ToolboxBitmapAttribute toolboxBitmapAttribute = (ToolboxBitmapAttribute)attr; images[t.FullName + ".bmp"] = il.Images.Count; Bitmap b = new Bitmap(toolboxBitmapAttribute.GetImage(t)); b.MakeTransparent(Color.Fuchsia); il.Images.Add(b); break; } } } } ListViewItem newItem = new ListViewItem(t.Name); newItem.SubItems.Add(t.Namespace); newItem.SubItems.Add(assembly.ToString()); newItem.SubItems.Add(assembly.Location); newItem.SubItems.Add(t.Namespace); if (images[t.FullName + ".bmp"] != null) { newItem.ImageIndex = (int)images[t.FullName + ".bmp"]; } newItem.Checked = true; ToolComponent toolComponent = new ToolComponent(t.FullName, new ComponentAssembly(assembly.FullName, loadPath), true); newItem.Tag = toolComponent; componentListView.Items.Add(newItem); ToolboxItem item = new ToolboxItem(t); skip :; } } } } catch (Exception e) { ClearComponentsList(e.Message); } } }
private void LoadReferences() { this.SuspendLayout(); this.imgImages.Images.Clear(); this.lstRecipes.Items.Clear(); GuidancePackage[] Packages = base.RecipeManagerService.GetEnabledPackages(); ArrayList images = new ArrayList(); // Add the two default images. ToolboxBitmapAttribute boundattr = new ToolboxBitmapAttribute(typeof(IBoundAssetReference)); Image boundimg = boundattr.GetImage(boundattr); this.imgImages.Images.Add(boundimg); // Add gray version this.imgImages.Images.Add(ConvertToGrayscale(boundimg)); ToolboxBitmapAttribute unboundattr = new ToolboxBitmapAttribute(typeof(IUnboundAssetReference)); Image unboundimg = unboundattr.GetImage(unboundattr); this.imgImages.Images.Add(unboundimg); // Add gray version this.imgImages.Images.Add(ConvertToGrayscale(unboundimg)); Hashtable groups = new Hashtable(); ArrayList items = new ArrayList(); // WORKAROUND: fixed for VSWhidbey "by design" bug #440390. Now we load items and groups // first, then sort everything manually, and finally add stuff to the control. // Commented lines should be documented when feature is fixed. foreach (GuidancePackage Package in Packages) { IAssetReferenceService refservice = (IAssetReferenceService) Package.GetService(typeof(IAssetReferenceService), true); IConfigurationService configService = (IConfigurationService)Package.GetService(typeof(IConfigurationService), true); foreach (IAssetReference reference in refservice.GetAll()) { ReferenceInfo info = new ReferenceInfo(reference); #region Determine image int imageindex = images.IndexOf(reference.GetType()); // Determine image to show. if (imageindex == -1) { ToolboxBitmapAttribute bmp = (ToolboxBitmapAttribute)Attribute.GetCustomAttribute( reference.GetType(), typeof(ToolboxBitmapAttribute), true); if (bmp == null) { // Use default attributes. if (reference is IBoundAssetReference) { imageindex = 0; } else { imageindex = 2; } if (!info.IsEnabled) { imageindex++; } } else { imageindex = this.imgImages.Images.Count; Image newimg = bmp.GetImage(reference); if (info.IsEnabled) { this.imgImages.Images.Add(newimg); } else { // Add gray version. this.imgImages.Images.Add(ConvertToGrayscale(newimg)); } images.Add(reference.GetType()); } } else { // Account for the 4 built-in images. imageindex = imageindex + 4; } #endregion Determine image #region Determine group // Bug: Should we fix this? // We should get custom attributes instead of a single attr. // The reference could override the category //CategoryAttribute category = (CategoryAttribute)Attribute.GetCustomAttribute( // reference.GetType(), typeof(CategoryAttribute), true); CategoryAttribute category = (CategoryAttribute)Attribute.GetCustomAttributes( reference.GetType(), typeof(CategoryAttribute), true).First(); // ListViewGroup categorygroup = this.lstRecipes.Groups[category.Category]; ListViewGroup categorygroup = (ListViewGroup)groups[category.Category]; if (categorygroup == null) { //categorygroup = this.lstRecipes.Groups.Add(category.Category, category.Category); categorygroup = new ListViewGroup(category.Category, category.Category); groups.Add(category.Category, categorygroup); } #endregion Determine group Config.Recipe recipe = null; if (reference is RecipeReference) { recipe = configService.CurrentPackage[reference.AssetName]; } string[] subitems = new string[3]; string errors = string.Empty; Exception ex = null; try { subitems[0] = reference.Caption; } catch (Exception e) { if (recipe != null) { subitems[0] = recipe.Caption; } ex = e; errors = "Caption"; } try { subitems[1] = reference.AppliesTo; } catch (Exception e) { subitems[1] = Configuration.Resources.Reference_AppliesToThrew; if (ex == null) { ex = e; } if (!string.IsNullOrEmpty(errors)) { errors += ", "; } errors += "AppliesTo"; } subitems[2] = Package.Configuration.Caption; ListViewItem item = new ListViewItem(subitems, imageindex); item.Tag = info; item.Group = categorygroup; items.Add(item); if (ex != null) { ErrorHelper.Show((IUIService)GetService(typeof(IUIService)), new RecipeExecutionException(reference.AssetName, string.Format(CultureInfo.CurrentCulture, Configuration.Resources.Reference_InvalidAttributes, errors), ex)); } } } // Sort everything. ListViewGroup[] lvgroups = new ListViewGroup[groups.Count]; groups.Values.CopyTo(lvgroups, 0); items.Sort(new ListViewItemSortComparer()); Array.Sort(lvgroups, new GroupSortComparer()); this.lstRecipes.Groups.AddRange(lvgroups); this.lstRecipes.Items.AddRange((ListViewItem[])items.ToArray(typeof(ListViewItem))); this.lstRecipes.Invalidate(); this.ResumeLayout(); if (this.lstRecipes.Items.Count > 0) { splitter.Panel1.Focus(); splitter.Panel1.Select(); ((ListViewItem)items[0]).Selected = true; this.lstRecipes.Focus(); this.lstRecipes.Select(); } else { this.txtDescription.Text = String.Empty; } }
public virtual void Initialize(Type type) { CheckUnlocked(); if (type != null) { TypeName = type.FullName; AssemblyName assemblyName = type.Assembly.GetName(true); if (type.Assembly.GlobalAssemblyCache) { assemblyName.CodeBase = null; } Dictionary <string, AssemblyName> parents = new Dictionary <string, AssemblyName>(); Type parentType = type; while (parentType != null) { AssemblyName policiedname = parentType.Assembly.GetName(true); AssemblyName aname = GetNonRetargetedAssemblyName(type, policiedname); if (aname != null && !parents.ContainsKey(aname.FullName)) { parents[aname.FullName] = aname; } parentType = parentType.BaseType; } AssemblyName[] parentAssemblies = new AssemblyName[parents.Count]; int i = 0; foreach (AssemblyName an in parents.Values) { parentAssemblies[i++] = an; } this.DependentAssemblies = parentAssemblies; AssemblyName = assemblyName; DisplayName = type.Name; //if the Type is a reflectonly type, these values must be set through a config object or manually //after construction. if (!type.Assembly.ReflectionOnly) { object[] companyattrs = type.Assembly.GetCustomAttributes(typeof(AssemblyCompanyAttribute), true); if (companyattrs != null && companyattrs.Length > 0) { AssemblyCompanyAttribute company = companyattrs[0] as AssemblyCompanyAttribute; if (company != null && company.Company != null) { Company = company.Company; } } //set the description based off the description attribute of the given type. DescriptionAttribute descattr = (DescriptionAttribute)TypeDescriptor.GetAttributes(type)[typeof(DescriptionAttribute)]; if (descattr != null) { this.Description = descattr.Description; } ToolboxBitmapAttribute attr = (ToolboxBitmapAttribute)TypeDescriptor.GetAttributes(type)[typeof(ToolboxBitmapAttribute)]; if (attr != null) { Bitmap itemBitmap = attr.GetImage(type, false) as Bitmap; if (itemBitmap != null) { // Original bitmap is used when adding the item to the Visual Studio toolbox // if running on a machine with HDPI scaling enabled. OriginalBitmap = attr.GetOriginalBitmap(); if ((itemBitmap.Width != iconWidth || itemBitmap.Height != iconHeight)) { itemBitmap = new Bitmap(itemBitmap, new Size(iconWidth, iconHeight)); } } Bitmap = itemBitmap; } bool filterContainsType = false; ArrayList array = new ArrayList(); foreach (Attribute a in TypeDescriptor.GetAttributes(type)) { ToolboxItemFilterAttribute ta = a as ToolboxItemFilterAttribute; if (ta != null) { if (ta.FilterString.Equals(TypeName)) { filterContainsType = true; } array.Add(ta); } } if (!filterContainsType) { array.Add(new ToolboxItemFilterAttribute(TypeName)); } Filter = (ToolboxItemFilterAttribute[])array.ToArray(typeof(ToolboxItemFilterAttribute)); } } }
private void PopulateToolBox(IToolboxService toolbox) { ToolboxList.Clear(); NavBarItem item; item = toolboxTabList.Items.Add(); item.Caption = "指针"; item.SmallImage = global::QueryDesigner.Properties.Resources._5; toolCommon.ItemLinks.Add(item); ToolboxItem toolboxItem = new ToolboxItem(typeof(Label)); item = toolboxTabList.Items.Add(); item.Caption = "Label"; ToolboxBitmapAttribute toolboxBitmap = new ToolboxBitmapAttribute(typeof(System.Windows.Forms.Label)); item.SmallImage = toolboxBitmap.GetImage(typeof(System.Windows.Forms.Label)); toolCommon.ItemLinks.Add(item); toolbox.AddToolboxItem(toolboxItem); ToolboxList.Add(item, toolboxItem); toolboxItem = new ToolboxItem(typeof(SnControl.ParamTextBox)); item = toolboxTabList.Items.Add(); item.Caption = "TextBox"; toolboxBitmap = new ToolboxBitmapAttribute(typeof(System.Windows.Forms.TextBox)); item.SmallImage = toolboxBitmap.GetImage(typeof(System.Windows.Forms.TextBox)); toolCommon.ItemLinks.Add(item); toolbox.AddToolboxItem(toolboxItem); ToolboxList.Add(item, toolboxItem); toolboxItem = new ToolboxItem(typeof(SnControl.ParamComboBox)); item = toolboxTabList.Items.Add(); item.Caption = "ComboBox"; toolboxBitmap = new ToolboxBitmapAttribute(typeof(System.Windows.Forms.ComboBox)); item.SmallImage = toolboxBitmap.GetImage(typeof(System.Windows.Forms.ComboBox)); toolCommon.ItemLinks.Add(item); toolbox.AddToolboxItem(toolboxItem); ToolboxList.Add(item, toolboxItem); toolboxItem = new ToolboxItem(typeof(SnControl.ParamDateTimePicker)); item = toolboxTabList.Items.Add(); item.Caption = "DateTimePicker"; toolboxBitmap = new ToolboxBitmapAttribute(typeof(System.Windows.Forms.DateTimePicker)); item.SmallImage = toolboxBitmap.GetImage(typeof(System.Windows.Forms.DateTimePicker)); toolCommon.ItemLinks.Add(item); toolbox.AddToolboxItem(toolboxItem); ToolboxList.Add(item, toolboxItem); toolboxItem = new ToolboxItem(typeof(TabControl)); item = toolboxTabList.Items.Add(); item.Caption = "TabControl"; toolboxBitmap = new ToolboxBitmapAttribute(typeof(System.Windows.Forms.TabControl)); item.SmallImage = toolboxBitmap.GetImage(typeof(System.Windows.Forms.TabControl)); toolCommon.ItemLinks.Add(item); toolbox.AddToolboxItem(toolboxItem); ToolboxList.Add(item, toolboxItem); toolboxItem = new ToolboxItem(typeof(GroupBox)); item = toolboxTabList.Items.Add(); item.Caption = "GroupBox"; toolboxBitmap = new ToolboxBitmapAttribute(typeof(System.Windows.Forms.GroupBox)); item.SmallImage = toolboxBitmap.GetImage(typeof(System.Windows.Forms.GroupBox)); toolCommon.ItemLinks.Add(item); toolbox.AddToolboxItem(toolboxItem); ToolboxList.Add(item, toolboxItem); toolboxItem = new ToolboxItem(typeof(Panel)); item = toolboxTabList.Items.Add(); item.Caption = "Panel"; toolboxBitmap = new ToolboxBitmapAttribute(typeof(System.Windows.Forms.Panel)); item.SmallImage = toolboxBitmap.GetImage(typeof(System.Windows.Forms.Panel)); toolCommon.ItemLinks.Add(item); toolbox.AddToolboxItem(toolboxItem); ToolboxList.Add(item, toolboxItem); toolboxItem = new ToolboxItem(typeof(System.Windows.Forms.DataGridView)); item = toolboxTabList.Items.Add(); item.Caption = "DataGridView"; toolboxBitmap = new ToolboxBitmapAttribute(typeof(System.Windows.Forms.DataGridView)); item.SmallImage = toolboxBitmap.GetImage(typeof(System.Windows.Forms.DataGridView)); toolCommon.ItemLinks.Add(item); toolbox.AddToolboxItem(toolboxItem); ToolboxList.Add(item, toolboxItem); toolboxItem = new ToolboxItem(typeof(TitlePanel)); item = toolboxTabList.Items.Add(); item.Caption = "TitlePanel"; toolboxBitmap = new ToolboxBitmapAttribute(typeof(System.Windows.Forms.GroupBox)); item.SmallImage = toolboxBitmap.GetImage(typeof(System.Windows.Forms.GroupBox)); toolCommon.ItemLinks.Add(item); toolbox.AddToolboxItem(toolboxItem); ToolboxList.Add(item, toolboxItem); toolboxItem = new ToolboxItem(typeof(SnControl.Search)); item = toolboxTabList.Items.Add(); item.Caption = "Search"; toolboxBitmap = new ToolboxBitmapAttribute(typeof(System.Windows.Forms.ComboBox)); item.SmallImage = Resources.Search; toolCommon.ItemLinks.Add(item); toolbox.AddToolboxItem(toolboxItem); ToolboxList.Add(item, toolboxItem); toolboxItem = new ToolboxItem(typeof(SnControl.ParamRadioButton)); item = toolboxTabList.Items.Add(); item.Caption = "RadioButton"; toolboxBitmap = new ToolboxBitmapAttribute(typeof(RadioButton)); item.SmallImage = toolboxBitmap.GetImage(typeof(RadioButton)); toolCommon.ItemLinks.Add(item); toolbox.AddToolboxItem(toolboxItem); ToolboxList.Add(item, toolboxItem); }