public static void SetIcon(this ImageList @this, Pictogram pictogram, object type, int size = 0, Color?color = null, Brush brush = null) { if (size == 0) { size = (@this.ImageSize.Width + @this.ImageSize.Height) / 2; } if (color == null) { color = SystemColors.ControlText; } if (brush == null) { brush = new SolidBrush(color.Value); } var image = pictogram.GetImage((int)type, size, brush); var hIcon = new Bitmap(image).GetHicon(); var icon = Icon.FromHandle(hIcon); @this.Images.Add(icon); }
public static void SetImage(this Control @this, Pictogram pictogram, object type, int size = 0, Color?color = null, Brush brush = null) { if (size == 0) { size = (@this.Width + @this.Height) / 2; } if (color == null) { color = @this.ForeColor; } if (brush == null) { brush = new SolidBrush(color.Value); } var image = pictogram.GetImage((int)type, size, brush); if (typeof(ButtonBase).IsAssignableFrom(@this.GetType())) { (@this as ButtonBase).Image = image; } if (typeof(PictureBox).IsAssignableFrom(@this.GetType())) { (@this as PictureBox).Image = image; } if (typeof(Panel).IsAssignableFrom(@this.GetType())) { (@this as Panel).BackgroundImage = image; } if (typeof(GroupBox).IsAssignableFrom(@this.GetType())) { (@this as GroupBox).BackgroundImage = image; } }
public static void SetImage(this Component @this, Pictogram pictogram, object type, int size = 0, Color?color = null, Brush brush = null) { if (typeof(ToolStripItem).IsAssignableFrom(@this.GetType())) { if (size == 0) { size = ((@this as ToolStripItem).Width + (@this as ToolStripItem).Height) / 2; } if (color == null) { color = (@this as ToolStripItem).ForeColor; } if (brush == null) { brush = new SolidBrush(color.Value); } var image = pictogram.GetImage((int)type, size, brush); (@this as ToolStripItem).Image = image; } else if (typeof(NotifyIcon).IsAssignableFrom(@this.GetType())) { if (size == 0) { size = 16; } if (color == null) { color = SystemColors.ControlText; } if (brush == null) { brush = new SolidBrush(color.Value); } var image = pictogram.GetImage((int)type, size, brush); var hIcon = new Bitmap(image).GetHicon(); (@this as NotifyIcon).Icon = Icon.FromHandle(hIcon); } else if (typeof(ImageList).IsAssignableFrom(@this.GetType())) { if (size == 0) { size = ((@this as ImageList).ImageSize.Width + (@this as ImageList).ImageSize.Height) / 2; } if (color == null) { color = SystemColors.ControlText; } if (brush == null) { brush = new SolidBrush(color.Value); } var image = pictogram.GetImage((int)type, size, brush); (@this as ImageList).Images.Add(image); } }