Converted PopulateSystemIcons into an extension method
This commit is contained in:
parent
d0cb32b089
commit
ea7f0daeca
@ -17,8 +17,8 @@ namespace UniversalEditor.UserInterface.WindowsForms.Controls
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
IconMethods.PopulateSystemIcons(ref imlLargeIcons);
|
||||
IconMethods.PopulateSystemIcons(ref imlSmallIcons);
|
||||
imlLargeIcons.PopulateSystemIcons();
|
||||
imlSmallIcons.PopulateSystemIcons();
|
||||
}
|
||||
|
||||
protected override void OnCreateControl()
|
||||
|
||||
@ -17,8 +17,8 @@ namespace UniversalEditor.UserInterface.WindowsForms.Controls
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
IconMethods.PopulateSystemIcons(ref imlSmallIcons);
|
||||
IconMethods.PopulateSystemIcons(ref imlLargeIcons);
|
||||
imlSmallIcons.PopulateSystemIcons();
|
||||
imlLargeIcons.PopulateSystemIcons();
|
||||
}
|
||||
|
||||
public bool ShowFavorites
|
||||
|
||||
@ -104,7 +104,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
|
||||
mvarLargeImageList.ColorDepth = ColorDepth.Depth32Bit;
|
||||
mvarLargeImageList.ImageSize = new System.Drawing.Size(32, 32);
|
||||
IconMethods.PopulateSystemIcons(ref mvarLargeImageList);
|
||||
mvarLargeImageList.PopulateSystemIcons();
|
||||
|
||||
string largeImageListPath = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[]
|
||||
{
|
||||
@ -131,7 +131,7 @@ namespace UniversalEditor.UserInterface.WindowsForms
|
||||
|
||||
mvarSmallImageList.ColorDepth = ColorDepth.Depth32Bit;
|
||||
mvarSmallImageList.ImageSize = new System.Drawing.Size(16, 16);
|
||||
IconMethods.PopulateSystemIcons(ref mvarSmallImageList);
|
||||
mvarSmallImageList.PopulateSystemIcons();
|
||||
|
||||
string smallImageListPath = String.Join(System.IO.Path.DirectorySeparatorChar.ToString(), new string[]
|
||||
{
|
||||
|
||||
@ -31,8 +31,8 @@ namespace UniversalEditor.UserInterface.WindowsForms.Editors
|
||||
|
||||
ImageList large = base.LargeImageList;
|
||||
ImageList small = base.SmallImageList;
|
||||
IconMethods.PopulateSystemIcons(ref large);
|
||||
IconMethods.PopulateSystemIcons(ref small);
|
||||
large.PopulateSystemIcons();
|
||||
small.PopulateSystemIcons();
|
||||
|
||||
lv.LargeImageList = base.LargeImageList;
|
||||
lv.SmallImageList = base.SmallImageList;
|
||||
|
||||
@ -201,50 +201,4 @@ internal static class IconMethods
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
|
||||
public static void PopulateSystemIcons(ref System.Windows.Forms.ImageList iml)
|
||||
{
|
||||
switch (Environment.OSVersion.Platform)
|
||||
{
|
||||
case PlatformID.MacOSX:
|
||||
break;
|
||||
case PlatformID.Unix:
|
||||
break;
|
||||
case PlatformID.Win32NT:
|
||||
case PlatformID.Win32S:
|
||||
case PlatformID.Win32Windows:
|
||||
case PlatformID.WinCE:
|
||||
{
|
||||
if (iml.ImageSize.Width == 16 && iml.ImageSize.Height == 16)
|
||||
{
|
||||
Icon iconFile = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 0, IconSize.Small);
|
||||
iml.Images.Add("generic-file", iconFile);
|
||||
Icon iconDocument = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 1, IconSize.Small);
|
||||
iml.Images.Add("generic-document", iconDocument);
|
||||
Icon iconApplication = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 2, IconSize.Small);
|
||||
iml.Images.Add("generic-application", iconApplication);
|
||||
Icon iconFolderClosed = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 3, IconSize.Small);
|
||||
iml.Images.Add("generic-folder-closed", iconFolderClosed);
|
||||
Icon iconFolderOpen = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 4, IconSize.Small);
|
||||
iml.Images.Add("generic-folder-open", iconFolderOpen);
|
||||
}
|
||||
else
|
||||
{
|
||||
Icon iconFile = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 0, IconSize.Large);
|
||||
iml.Images.Add("generic-file", iconFile);
|
||||
Icon iconDocument = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 1, IconSize.Large);
|
||||
iml.Images.Add("generic-document", iconDocument);
|
||||
Icon iconApplication = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 2, IconSize.Large);
|
||||
iml.Images.Add("generic-application", iconApplication);
|
||||
Icon iconFolderClosed = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 3, IconSize.Large);
|
||||
iml.Images.Add("generic-folder-closed", iconFolderClosed);
|
||||
Icon iconFolderOpen = ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 4, IconSize.Large);
|
||||
iml.Images.Add("generic-folder-open", iconFolderOpen);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
// throw new PlatformNotSupportedException();
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace UniversalEditor
|
||||
{
|
||||
public static class ImageListExtensionMethods
|
||||
{
|
||||
public static void PopulateSystemIcons(this System.Windows.Forms.TreeView tv)
|
||||
{
|
||||
System.Windows.Forms.ImageList iml = new System.Windows.Forms.ImageList();
|
||||
iml.ImageSize = new Size(16, 16);
|
||||
iml.PopulateSystemIcons();
|
||||
|
||||
tv.ImageList = iml;
|
||||
}
|
||||
public static void PopulateSystemIcons(this System.Windows.Forms.ListView lv)
|
||||
{
|
||||
System.Windows.Forms.ImageList imlSmallIcons = new System.Windows.Forms.ImageList();
|
||||
imlSmallIcons.ImageSize = new Size(16, 16);
|
||||
System.Windows.Forms.ImageList imlLargeIcons = new System.Windows.Forms.ImageList();
|
||||
imlLargeIcons.ImageSize = new Size(32, 32);
|
||||
|
||||
lv.LargeImageList = imlLargeIcons;
|
||||
lv.SmallImageList = imlSmallIcons;
|
||||
}
|
||||
public static void PopulateSystemIcons(this System.Windows.Forms.ImageList iml)
|
||||
{
|
||||
switch (Environment.OSVersion.Platform)
|
||||
{
|
||||
case PlatformID.MacOSX:
|
||||
break;
|
||||
case PlatformID.Unix:
|
||||
break;
|
||||
case PlatformID.Win32NT:
|
||||
case PlatformID.Win32S:
|
||||
case PlatformID.Win32Windows:
|
||||
case PlatformID.WinCE:
|
||||
{
|
||||
if (iml.ImageSize.Width == 16 && iml.ImageSize.Height == 16)
|
||||
{
|
||||
Icon iconFile = IconMethods.ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 0, IconMethods.IconSize.Small);
|
||||
iml.Images.Add("generic-file", iconFile);
|
||||
Icon iconDocument = IconMethods.ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 1, IconMethods.IconSize.Small);
|
||||
iml.Images.Add("generic-document", iconDocument);
|
||||
Icon iconApplication = IconMethods.ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 2, IconMethods.IconSize.Small);
|
||||
iml.Images.Add("generic-application", iconApplication);
|
||||
Icon iconFolderClosed = IconMethods.ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 3, IconMethods.IconSize.Small);
|
||||
iml.Images.Add("generic-folder-closed", iconFolderClosed);
|
||||
Icon iconFolderOpen = IconMethods.ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 4, IconMethods.IconSize.Small);
|
||||
iml.Images.Add("generic-folder-open", iconFolderOpen);
|
||||
}
|
||||
else
|
||||
{
|
||||
Icon iconFile = IconMethods.ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 0, IconMethods.IconSize.Large);
|
||||
iml.Images.Add("generic-file", iconFile);
|
||||
Icon iconDocument = IconMethods.ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 1, IconMethods.IconSize.Large);
|
||||
iml.Images.Add("generic-document", iconDocument);
|
||||
Icon iconApplication = IconMethods.ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 2, IconMethods.IconSize.Large);
|
||||
iml.Images.Add("generic-application", iconApplication);
|
||||
Icon iconFolderClosed = IconMethods.ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 3, IconMethods.IconSize.Large);
|
||||
iml.Images.Add("generic-folder-closed", iconFolderClosed);
|
||||
Icon iconFolderOpen = IconMethods.ExtractAssociatedIcon(Environment.GetFolderPath(Environment.SpecialFolder.System) + System.IO.Path.DirectorySeparatorChar + "shell32.dll", 4, IconMethods.IconSize.Large);
|
||||
iml.Images.Add("generic-folder-open", iconFolderOpen);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
// throw new PlatformNotSupportedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -128,6 +128,7 @@
|
||||
</Compile>
|
||||
<Compile Include="ExtensionMethods.cs" />
|
||||
<Compile Include="IconMethods.cs" />
|
||||
<Compile Include="ImageListExtensionMethods.cs" />
|
||||
<Compile Include="OptionPanel.cs">
|
||||
<SubType>UserControl</SubType>
|
||||
</Compile>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user