142 instantiations of Icon
DesignSurface (1)
System.Drawing.Common (12)
System.Drawing.Common.Tests (65)
System\Drawing\IconTests.cs (52)
40using Icon icon = new(Helpers.GetTestBitmapPath(name));
70using Icon icon = new(Helpers.GetTestBitmapPath(fileName), size.Width, size.Height);
80using Icon icon = new(Helpers.GetTestBitmapPath(fileName), size);
89AssertExtensions.Throws<ArgumentNullException>("path", () => new Icon((string)null));
90AssertExtensions.Throws<ArgumentNullException>("path", () => new Icon((string)null, new Size(32, 32)));
91AssertExtensions.Throws<ArgumentNullException>("path", () => new Icon((string)null, 32, 32));
98Icon icon = new(stream);
108Icon icon = new(stream);
125using Icon icon = new(stream, size.Width, size.Height);
136using Icon icon = new(stream, size);
145AssertExtensions.Throws<ArgumentNullException, ArgumentException>("stream", null, () => new Icon((Stream)null));
146AssertExtensions.Throws<ArgumentNullException, ArgumentException>("stream", null, () => new Icon((Stream)null, 32, 32));
147AssertExtensions.Throws<ArgumentNullException, ArgumentException>("stream", null, () => new Icon((Stream)null, new Size(32, 32)));
215Assert.Throws(exceptionType, () => new Icon(stream));
222using Icon sourceIcon = new(Helpers.GetTestBitmapPath(fileName));
223using Icon icon = new(sourceIcon, size.Width, size.Height);
234using Icon sourceIcon = new(Helpers.GetTestBitmapPath(fileName));
235using Icon icon = new(sourceIcon, size);
245AssertExtensions.Throws<ArgumentNullException, ArgumentException>("original", null, () => new Icon((Icon)null, 32, 32));
246AssertExtensions.Throws<ArgumentNullException, ArgumentException>("original", null, () => new Icon((Icon)null, new Size(32, 32)));
252using Icon icon = new(typeof(IconTests), "48x48_multiple_entries_4bit.ico");
260Assert.Throws<NullReferenceException>(() => new Icon(null, "48x48_multiple_entries_4bit.ico"));
269AssertExtensions.Throws<ArgumentException>(null, () => new Icon(type, resource));
275AssertExtensions.Throws<ArgumentNullException, ArgumentException>("resource", null, () => new Icon(typeof(Icon), null));
281using Icon icon = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
305Icon icon = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
322using Icon source = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
337using Icon icon = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_32bit.ico"), size, size);
425SaveAndCompare(new Icon(Helpers.GetTestBitmapPath(fileName)), true);
432using Icon icon = new(filePath);
442Icon icon = new(filePath);
452using Icon icon = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
459using Icon source = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
469using Icon icon = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
479using Icon source = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
507yield return new object[] { new Icon(Helpers.GetTestBitmapPath("16x16_one_entry_4bit.ico")) };
508yield return new object[] { new Icon(Helpers.GetTestBitmapPath("32x32_one_entry_4bit.ico")) };
509yield return new object[] { new Icon(Helpers.GetTestBitmapPath("48x48_one_entry_1bit.ico")) };
510yield return new object[] { new Icon(Helpers.GetTestBitmapPath("64x64_one_entry_8bit.ico")) };
511yield return new object[] { new Icon(Helpers.GetTestBitmapPath("96x96_one_entry_8bit.ico")) };
512yield return new object[] { new Icon(Helpers.GetTestBitmapPath("256x256_two_entries_multiple_bits.ico"), 48, 48) };
513yield return new object[] { new Icon(Helpers.GetTestBitmapPath("256x256_two_entries_multiple_bits.ico"), 256, 256) };
514yield return new object[] { new Icon(Helpers.GetTestBitmapPath("256x256_two_entries_multiple_bits.ico"), 0, 0) };
544using Icon originalIcon = new(Helpers.GetTestBitmapPath("48x48_one_entry_1bit.ico"));
630return new Icon(stream);
636using Icon icon1 = new(Helpers.GetTestBitmapPath("16x16_one_entry_4bit.ico"));
646using Icon icon1 = new(Helpers.GetTestBitmapPath("16x16_one_entry_4bit.ico"));
664using (Icon icon1 = new(Helpers.GetTestBitmapPath("16x16_one_entry_4bit.ico")))
679using (Icon icon1 = new(Helpers.GetTestBitmapPath("16x16_one_entry_4bit.ico")))
706Icon icon = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
720using Icon loaded = new(outputStream);
751using Icon icon = new(stream, new Size(32, 32));
System.Windows.Forms (8)
System.Windows.Forms.Design (21)
System.Windows.Forms.Design.Tests (4)
System.Windows.Forms.Primitives (2)
System.Windows.Forms.Tests (29)
334 references to Icon
DesignSurface (1)
Microsoft.CodeAnalysis.CSharp.EditorFeatures.UnitTests (1)
Microsoft.CodeAnalysis.EditorFeatures.Wpf (1)
PresentationUI (13)
System.Drawing (1)
System.Drawing.Common (56)
System\Drawing\Icon.cs (20)
48throw new ArgumentException(SR.Format(SR.InvalidGDIHandle, nameof(Icon)));
74public Icon(Icon original, Size size) : this(original, size.Width, size.Height)
78public Icon(Icon original, int width, int height) : this()
149public static Icon? ExtractAssociatedIcon(string filePath) => ExtractAssociatedIcon(filePath, 0);
151private static Icon? ExtractAssociatedIcon(string filePath, int index)
393public static Icon FromHandle(IntPtr handle)
417throw new ArgumentException(SR.Format(SR.InvalidPictureType, "picture", nameof(Icon)));
451throw new ArgumentException(SR.Format(SR.InvalidPictureType, "picture", nameof(Icon)));
516throw new ArgumentException(SR.Format(SR.InvalidPictureType, "picture", nameof(Icon)));
536throw new ArgumentException(SR.Format(SR.InvalidPictureType, "picture", nameof(Icon)));
788/// Saves this <see cref="Icon"/> to the specified output <see cref="Stream"/>.
820/// original data (outside of resizing if necessary). As such, the <see cref="Icon"/> only uses as much
824/// Without the original source data the <see cref="Icon(Icon, Size)">copy constructors</see> have to resample
825/// the current icon's bitmap to change sizes. For best image quality, if different sizes for an <see cref="Icon"/>
839/// An <see cref="Icon"/>, or <see langword="null"/> if an icon can't be found with the specified
851public static Icon? ExtractIcon(string filePath, int id, int size)
857/// If <see langword="true"/>, gets the <see cref="Icon"/> at the current system small icon size setting. If
858/// <see langword="false"/>, gets the <see cref="Icon"/> at the current system large icon size setting. Default is
862public static Icon? ExtractIcon(string filePath, int id, bool smallIcon = false)
865private static Icon? ExtractIcon(string filePath, int id, int size, bool smallIcon = false)
System\Drawing\SystemIcons.cs (26)
11private static Icon? s_application;
12private static Icon? s_asterisk;
13private static Icon? s_error;
14private static Icon? s_exclamation;
15private static Icon? s_hand;
16private static Icon? s_information;
17private static Icon? s_question;
18private static Icon? s_warning;
19private static Icon? s_winlogo;
20private static Icon? s_shield;
22public static Icon Application => GetIcon(ref s_application, PInvokeCore.IDI_APPLICATION);
24public static Icon Asterisk => GetIcon(ref s_asterisk, PInvokeCore.IDI_ASTERISK);
26public static Icon Error => GetIcon(ref s_error, PInvokeCore.IDI_ERROR);
28public static Icon Exclamation => GetIcon(ref s_exclamation, PInvokeCore.IDI_EXCLAMATION);
30public static Icon Hand => GetIcon(ref s_hand, PInvokeCore.IDI_HAND);
32public static Icon Information => GetIcon(ref s_information, PInvokeCore.IDI_INFORMATION);
34public static Icon Question => GetIcon(ref s_question, PInvokeCore.IDI_QUESTION);
36public static Icon Warning => GetIcon(ref s_warning, PInvokeCore.IDI_WARNING);
38public static Icon WinLogo => GetIcon(ref s_winlogo, PInvokeCore.IDI_WINLOGO);
40public static Icon Shield => s_shield ??= new Icon(typeof(SystemIcons), "ShieldIcon.ico");
42private static Icon GetIcon(ref Icon? icon, PCWSTR iconId) =>
51/// <returns>The requested <see cref="Icon"/>.</returns>
55/// for the running version of Windows. Additionally, the returned <see cref="Icon"/> is not cached and
60public static unsafe Icon GetStockIcon(StockIconId stockIcon, StockIconOptions options = StockIconOptions.Default)
86public static unsafe Icon GetStockIcon(StockIconId stockIcon, int size)
System.Drawing.Common.Tests (113)
System\Drawing\IconTests.cs (92)
40using Icon icon = new(Helpers.GetTestBitmapPath(name));
70using Icon icon = new(Helpers.GetTestBitmapPath(fileName), size.Width, size.Height);
80using Icon icon = new(Helpers.GetTestBitmapPath(fileName), size);
98Icon icon = new(stream);
108Icon icon = new(stream);
125using Icon icon = new(stream, size.Width, size.Height);
136using Icon icon = new(stream, size);
222using Icon sourceIcon = new(Helpers.GetTestBitmapPath(fileName));
223using Icon icon = new(sourceIcon, size.Width, size.Height);
234using Icon sourceIcon = new(Helpers.GetTestBitmapPath(fileName));
235using Icon icon = new(sourceIcon, size);
245AssertExtensions.Throws<ArgumentNullException, ArgumentException>("original", null, () => new Icon((Icon)null, 32, 32));
246AssertExtensions.Throws<ArgumentNullException, ArgumentException>("original", null, () => new Icon((Icon)null, new Size(32, 32)));
252using Icon icon = new(typeof(IconTests), "48x48_multiple_entries_4bit.ico");
264[InlineData(typeof(Icon), "")]
265[InlineData(typeof(Icon), "48x48_multiple_entries_4bit.ico")]
275AssertExtensions.Throws<ArgumentNullException, ArgumentException>("resource", null, () => new Icon(typeof(Icon), null));
281using Icon icon = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
282using Icon clone = Assert.IsType<Icon>(icon.Clone());
293using var icon = Icon.FromHandle(SystemIcons.Hand.Handle);
294using Icon clone = Assert.IsType<Icon>(icon.Clone());
305Icon icon = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
313Icon icon = Icon.ExtractAssociatedIcon(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
322using Icon source = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
323using var icon = Icon.FromHandle(source.Handle);
337using Icon icon = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_32bit.ico"), size, size);
379using Icon icon = Icon.ExtractAssociatedIcon(filePath);
390Assert.Null(Icon.ExtractAssociatedIcon("http://microsoft.com"));
394Assert.Throws<FileNotFoundException>(() => Icon.ExtractAssociatedIcon("http://microsoft.com"));
401AssertExtensions.Throws<ArgumentNullException, ArgumentException>("filePath", null, () => Icon.ExtractAssociatedIcon(null));
407AssertExtensions.Throws<ArgumentException>("filePath", null, () => Icon.ExtractAssociatedIcon(""));
413Assert.Throws<FileNotFoundException>(() => Icon.ExtractAssociatedIcon("no-such-file.png"));
432using Icon icon = new(filePath);
442Icon icon = new(filePath);
452using Icon icon = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
459using Icon source = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
460var icon = Icon.FromHandle(source.Handle);
469using Icon icon = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
479using Icon source = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
480using var icon = Icon.FromHandle(source.Handle);
499Icon icon = Icon.ExtractAssociatedIcon(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
519public void ToBitmap_BitmapIcon_ReturnsExpected(Icon icon)
544using Icon originalIcon = new(Helpers.GetTestBitmapPath("48x48_one_entry_1bit.ico"));
545using Icon icon = Icon.FromHandle(originalIcon.Handle);
556using Icon icon = GetPngIcon();
591using Icon icon = GetPngIcon();
610private static Icon GetPngIcon()
636using Icon icon1 = new(Helpers.GetTestBitmapPath("16x16_one_entry_4bit.ico"));
637using Icon icon2 = Icon.FromHandle(icon1.Handle);
646using Icon icon1 = new(Helpers.GetTestBitmapPath("16x16_one_entry_4bit.ico"));
647using (Icon icon2 = Icon.FromHandle(icon1.Handle))
654using Icon icon3 = Icon.FromHandle(icon1.Handle);
664using (Icon icon1 = new(Helpers.GetTestBitmapPath("16x16_one_entry_4bit.ico")))
669using Icon icon2 = Icon.FromHandle(handle);
679using (Icon icon1 = new(Helpers.GetTestBitmapPath("16x16_one_entry_4bit.ico")))
684using (Icon icon2 = Icon.FromHandle(handle))
691using Icon icon3 = Icon.FromHandle(handle);
700AssertExtensions.Throws<ArgumentException>("handle", null, () => Icon.FromHandle(IntPtr.Zero));
706Icon icon = new(Helpers.GetTestBitmapPath("48x48_multiple_entries_4bit.ico"));
714private static void SaveAndCompare(Icon icon, bool alpha)
720using Icon loaded = new(outputStream);
751using Icon icon = new(stream, new Size(32, 32));
758FieldInfo fi = typeof(Icon).GetField(fieldName, BindingFlags.Static | BindingFlags.NonPublic);
786Assert.Throws<ArgumentNullException>(() => { Icon.ExtractIcon(null!, 0, 16); });
787Assert.Throws<ArgumentNullException>(() => { Icon.ExtractIcon(null!, 0); });
793Assert.Throws<IOException>(() => { Icon.ExtractIcon(string.Empty, 0, 16); });
794Assert.Throws<IOException>(() => { Icon.ExtractIcon(string.Empty, 0); });
804Assert.Throws<ArgumentOutOfRangeException>(() => { Icon.ExtractIcon("Foo", 0, size); });
812Icon.ExtractIcon(Path.GetRandomFileName() + ".ico", 0, 16);
817Icon.ExtractIcon(Path.GetRandomFileName() + ".ico", 0);
825Assert.Null(Icon.ExtractIcon(file.Path, 0, 16));
826Assert.Null(Icon.ExtractIcon(file.Path, 0));
832Icon? icon;
834while ((icon = Icon.ExtractIcon("regedit.exe", count, 16)) is not null)
850using Icon? icon = Icon.ExtractIcon("regedit.exe", -100, 256);
System.Windows.Forms (65)
System.Windows.Forms.Design (4)
System.Windows.Forms.Design.Tests (11)
System.Windows.Forms.Primitives (4)
System.Windows.Forms.Primitives.Tests (5)
System.Windows.Forms.Tests (57)
TestPassApp (1)
WinFormsControlsTest (1)