本文整理汇总了C#中IconSize类的典型用法代码示例。如果您正苦于以下问题:C# IconSize类的具体用法?C# IconSize怎么用?C# IconSize使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IconSize类属于命名空间,在下文中一共展示了IconSize类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DropDownToolbarItem
public DropDownToolbarItem(IDropDownAction action, IconSize iconSize)
{
_action = action;
_actionEnabledChangedHandler = new EventHandler(OnActionEnabledChanged);
_actionVisibleChangedHandler = new EventHandler(OnActionVisibleChanged);
_actionAvailableChangedHandler = new EventHandler(OnActionAvailableChanged);
_actionLabelChangedHandler = new EventHandler(OnActionLabelChanged);
_actionTooltipChangedHandler = new EventHandler(OnActionTooltipChanged);
_actionIconSetChangedHandler = new EventHandler(OnActionIconSetChanged);
_action.EnabledChanged += _actionEnabledChangedHandler;
_action.VisibleChanged += _actionVisibleChangedHandler;
_action.AvailableChanged += _actionAvailableChangedHandler;
_action.LabelChanged += _actionLabelChangedHandler;
_action.TooltipChanged += _actionTooltipChangedHandler;
_action.IconSetChanged += _actionIconSetChangedHandler;
_iconSize = iconSize;
this.Text = _action.Label;
this.Enabled = _action.Enabled;
this.Visible = _action.Visible;
this.ToolTipText = _action.Tooltip;
UpdateVisibility();
UpdateEnablement();
UpdateIcon();
this.ShowDropDownArrow = true;
this.DropDown = new ContextMenuStrip();
this.DropDown.ImageScalingSize = StandardIconSizes.Small;
this.DropDownOpening += new EventHandler(OnDropDownOpening);
}
示例2: ResolveIcon
/// <summary>
/// Resolves icon of the file.
/// </summary>
/// <param name="fileExtensionName">The file extension name.</param>
/// <param name="iconSize">The icon size.</param>
/// <returns></returns>
public Stream ResolveIcon(string fileExtensionName, IconSize iconSize)
{
string iconManifestPath = string.Empty;
switch (iconSize)
{
case IconSize.Pixel16x16:
iconManifestPath = string.Format(SmallIconManifestPathTemplate, fileExtensionName.ToLower());
break;
case IconSize.Pixel50x50:
iconManifestPath = string.Format(LargeIconManifestPathTemplate, fileExtensionName.ToLower());
break;
}
Stream stream = typeof(FileIconApi).Assembly.GetManifestResourceStream(iconManifestPath);
if (stream == null || stream.Length == 0)
{
switch (iconSize)
{
case IconSize.Pixel16x16:
stream = typeof(FileIconApi).Assembly.GetManifestResourceStream(SmallMiscellaneousIconManifestPath);
break;
case IconSize.Pixel50x50:
stream = typeof(FileIconApi).Assembly.GetManifestResourceStream(LargeMiscellaneousIconManifestPath);
break;
}
}
return stream;
}
示例3: GetIconData
public static Bitmap GetIconData(string iconId, IconSize iconSize)
{
var hash = StockIconCodon.ComputeHashCode(iconId, iconSize);
if (IconData.ContainsKey(hash))
return IconData[hash];
if (!IconStock.ContainsKey(hash))
throw new Exception("Icon "+iconId+" not available!");
var iconCodon = IconStock[hash];
if (!string.IsNullOrEmpty (iconCodon.Resource) || !string.IsNullOrEmpty (iconCodon.File)) {
Bitmap bitmap;
Stream stream;
if (iconCodon.Resource != null)
stream = iconCodon.Addin.GetResource (iconCodon.Resource);
else
stream = File.OpenRead (iconCodon.Addin.GetFilePath (iconCodon.File));
using (stream) {
if (stream == null || stream.Length < 0) {
throw new Exception(string.Format("Did not find resource '{0}' in addin '{1}' for icon '{2}'",
iconCodon.Resource, iconCodon.Addin.Id, iconCodon.StockId));
}
bitmap = (Bitmap) Image.FromStream(stream);
}
IconData[hash] = bitmap;
}
return IconData[hash];
}
示例4: GetDirectoryIcon
public static ImageSource GetDirectoryIcon(string path, int iconIndex, IconSize size = IconSize.Small)
{
ImageSource imageSource = null;
if (IconsDictionary.TryGetValue(iconIndex, out imageSource))
{
return imageSource;
}
Int32Rect sizeRect;
WinAPI.SHGFI flags;
if (IconSize.Small == size)
{
flags = commonFlags | WinAPI.SHGFI.SHGFI_SMALLICON;
sizeRect = new Int32Rect(0, 0, 16, 16);
}
else
{
flags = commonFlags | WinAPI.SHGFI.SHGFI_LARGEICON;
sizeRect = new Int32Rect(0, 0, 32, 32);
}
WinAPI.SHFILEINFO shfileinfo = new WinAPI.SHFILEINFO();
WinAPI.SHGetFileInfo(path, 256, out shfileinfo, (uint) Marshal.SizeOf(shfileinfo), flags);
if (shfileinfo.hIcon == IntPtr.Zero)
{
return GetIcon(path);
}
imageSource = Imaging.CreateBitmapSourceFromHIcon(shfileinfo.hIcon, sizeRect,
BitmapSizeOptions.FromEmptyOptions());
IconsDictionary.Add(iconIndex, imageSource);
WinAPI.DestroyIcon(shfileinfo.hIcon);
shfileinfo.hIcon = IntPtr.Zero;
return imageSource;
}
示例5: GetFileIcon
/// <summary>
/// Returns an icon for a given file - indicated by the Name parameter.
/// </summary>
/// <param Name="Name">Pathname for file.</param>
/// <param Name="size">Large or small</param>
/// <param Name="linkOverlay">Whether to include the link icon</param>
/// <returns>System.Drawing.Icon</returns>
public static Icon GetFileIcon(string name, IconSize size, bool linkOverlay)
{
Shell32.SHFILEINFO shfi = new Shell32.SHFILEINFO();
uint flags = Shell32.SHGFI_ICON | Shell32.SHGFI_USEFILEATTRIBUTES;
if (linkOverlay) flags += Shell32.SHGFI_LINKOVERLAY;
/* Check the size specified for return. */
if (IconSize.Small == size)
{
flags += Shell32.SHGFI_SMALLICON;
}
else
{
flags += Shell32.SHGFI_LARGEICON;
}
Shell32.SHGetFileInfo(name,
Shell32.FILE_ATTRIBUTE_NORMAL,
ref shfi,
(uint)Marshal.SizeOf(shfi),
flags);
Icon.FromHandle(shfi.hIcon); // Load the icon from an HICON handle
// Now clone the icon, so that it can be successfully stored in an ImageList
Icon icon = (Icon)Icon.FromHandle(shfi.hIcon).Clone();
return icon;
}
示例6: GetFileIcon
/// <summary>
/// Returns an icon for a given file - indicated by the name parameter.
/// </summary>
/// <param name="name">Pathname for file.</param>
/// <param name="size">Large or small</param>
/// <param name="linkOverlay">Whether to include the link icon</param>
/// <returns>Icon</returns>
public static Icon GetFileIcon(string name, IconSize size, bool linkOverlay)
{
var shfi = new Shell32.SHFILEINFO();
var flags = Shell32.SHGFI_ICON | Shell32.SHGFI_USEFILEATTRIBUTES;
if (linkOverlay) flags += Shell32.SHGFI_LINKOVERLAY;
/* Check the size specified for return. */
if (IconSize.Small == size) {
flags += Shell32.SHGFI_SMALLICON;
} else {
flags += Shell32.SHGFI_LARGEICON;
}
//Shell32.SHGetFileInfo(name,
// Shell32.FILE_ATTRIBUTE_NORMAL,
// ref shfi,
// (uint)Marshal.SizeOf(shfi),
// flags);
//// Copy (clone) the returned icon to a new object, thus allowing us to clean-up properly
//var icon = (Icon)Icon.FromHandle(shfi.hIcon).Clone();
//User32.DestroyIcon(shfi.hIcon); // Cleanup
//return icon;
return GetIcon(flags, name, Shell32.FILE_ATTRIBUTE_NORMAL);
}
示例7: GetImage
public Bitmap GetImage(IconSize imageSize)
{
if (!File.Exists(_imagePath))
return null;
if (PathEx.HasExtension(_imagePath, FileExtensions.Executable) ||
PathEx.HasExtension(_imagePath, FileExtensions.Shortcut) ||
PathEx.HasExtension(_imagePath, FileExtensions.Icon))
{
return GetIcon(imageSize);
}
try
{
return new Bitmap(_imagePath);
}
catch (ArgumentException ex)
{
// Unable to convert to an image, assume it's an exe/ico/lnk file even though the extension is wrong.
if (Log.IsDebugEnabled)
Log.DebugFormat("Failed to convert {0} to a image, trying to convert to an icon instead: {1}", _imagePath, ex);
return GetIcon(imageSize);
}
catch (IOException ex)
{
// Unable to convert to an image, assume it's an exe/ico/lnk file even though the extension is wrong.
if (Log.IsDebugEnabled)
Log.DebugFormat("Failed to convert {0} to a image, trying to convert to an icon instead: {1}", _imagePath, ex);
return GetIcon(imageSize);
}
}
示例8: GetFileBasedFSBitmap
protected Bitmap GetFileBasedFSBitmap(string ext, IconSize size)
{
string lookup = tempPath;
Bitmap folderBitmap = KeyToBitmap(lookup, size);
if (ext != "")
{
ext = ext.Substring(0, 1).ToUpper() + ext.Substring(1).ToLower();
using (Graphics g = Graphics.FromImage(folderBitmap))
{
g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.AntiAlias;
Font font = new Font("Comic Sans MS", folderBitmap.Width / 5, System.Drawing.FontStyle.Bold | System.Drawing.FontStyle.Italic);
float height = g.MeasureString(ext, font).Height;
float rightOffset = folderBitmap.Width / 5;
if (size == IconSize.small)
{
font = new Font("Arial", 5, System.Drawing.FontStyle.Bold);
height = g.MeasureString(ext, font).Height;
rightOffset = 0;
}
g.DrawString(ext, font,
System.Drawing.Brushes.Black,
new RectangleF(0, folderBitmap.Height - height, folderBitmap.Width - rightOffset, height),
new StringFormat(StringFormatFlags.DirectionRightToLeft));
}
}
return folderBitmap;
}
示例9: IconFromExtension
/// <summary>
/// Get Windows-Icon for the Extension of a file
/// </summary>
/// <param name="Extension">ext of tile</param>
/// <param name="Size">IconSize</param>
/// <returns>Icon for this extension</returns>
public static Icon IconFromExtension(string Extension, IconSize Size)
{
Icon icon = null;
try
{
//add '.' if necessary
if (Extension[0] != '.') Extension = '.' + Extension;
//search registry for the file extension
RegistryKey Root = Registry.ClassesRoot;
RegistryKey ExtensionKey = Root.OpenSubKey(Extension);
ExtensionKey.GetValueNames();
RegistryKey appKey = Root.OpenSubKey(ExtensionKey.GetValue("").ToString());
//gets the name of the file that has the icon.
string IconLocation = appKey.OpenSubKey("DefaultIcon").GetValue("").ToString();
string[] IconPath = IconLocation.Split(',');
if (IconPath[1] == null) IconPath[1] = "0";
IntPtr[] Large = new IntPtr[1];
IntPtr[] Small = new IntPtr[1];
//extracts the icon from the file.
ExtractIconEx(IconPath[0], Convert.ToInt16(IconPath[1]), Large, Small, 1);
icon = Size == IconSize.Large ? Icon.FromHandle(Large[0]) : Icon.FromHandle(Small[0]);
}
catch (Exception e)
{
Util.Debug("Icon konnte nicht extrahiert werden!", e);
}
return icon;
}
示例10: GetIcon
/// <summary>
/// Get system icon for specified folder/file
/// </summary>
/// <param name="path"> Full path to a folder or file </param>
/// <param name="type"> Type: folder or file </param>
/// <param name="size"> Icon size: small or large</param>
/// <param name="isOpen"> Is open icon (applicable for folders only) </param>
/// <returns></returns>
public static Icon GetIcon(string path, ItemType type, IconSize size, bool isOpen)
{
var flags = SHGFI_ICON | SHGFI_USEFILEATTRIBUTES;
var attribute = (type == ItemType.Folder) ? FILE_ATTRIBUTE_DIRECTORY : FILE_ATTRIBUTE_FILE;
if (isOpen)
flags += SHGFI_OPENICON;
if (size == IconSize.Small)
flags += SHGFI_SMALLICON;
else
flags += SHGFI_LARGEICON;
var shfi = new SHFileInfo();
var res = SHGetFileInfo(path, attribute, out shfi, (uint)Marshal.SizeOf(shfi), flags);
if (Equals(res, IntPtr.Zero))
throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());
try
{
Icon.FromHandle(shfi.hIcon);
return (Icon)Icon.FromHandle(shfi.hIcon).Clone();
}
finally
{
DestroyIcon(shfi.hIcon);
}
}
示例11: thumbnailInfo
public thumbnailInfo(WriteableBitmap b, string path, IconSize size, int rol)
{
bitmap = b;
fullPath = path;
iconsize = size;
roll = rol;
}
示例12: TextBoxToolbarItem
public TextBoxToolbarItem(ITextBoxAction action, IconSize iconSize)
{
_action = action;
_actionEnabledChangedHandler = new EventHandler(OnActionEnabledChanged);
_actionVisibleChangedHandler = new EventHandler(OnActionVisibleChanged);
_actionAvailableChangedHandler = new EventHandler(OnActionAvailableChanged);
_actionLabelChangedHandler = new EventHandler(OnActionLabelChanged);
_actionTooltipChangedHandler = new EventHandler(OnActionTooltipChanged);
_actionIconSetChangedHandler = new EventHandler(OnActionIconSetChanged);
_actionTextBoxValueChangedHandler = new EventHandler(OnActionTextBoxValueChanged);
_actionCueTextChangedHandler = new EventHandler(OnActionCueTextChanged);
_action.EnabledChanged += _actionEnabledChangedHandler;
_action.VisibleChanged += _actionVisibleChangedHandler;
_action.AvailableChanged += _actionAvailableChangedHandler;
_action.LabelChanged += _actionLabelChangedHandler;
_action.TooltipChanged += _actionTooltipChangedHandler;
_action.IconSetChanged += _actionIconSetChangedHandler;
_action.TextValueChanged += _actionTextBoxValueChangedHandler;
_action.CueTextChanged += _actionCueTextChangedHandler;
_iconSize = iconSize;
this.Text = _action.TextValue;
this.Enabled = _action.Enabled;
SetTooltipText();
UpdateCueBanner();
UpdateVisibility();
UpdateEnablement();
UpdateIcon();
}
示例13: GetDefaultDirectoryIcon
/// <summary>
/// The current Windows default Folder Icon in the given Size (Large/Small) as System.Drawing.Icon.
/// </summary>
/// <param name="size">The Size of the Icon (Small or Large).</param>
/// <param name="folderType">The folderTypeIcon (closed or Open).</param>
/// <returns>The Folder Icon as System.Drawing.Icon.</returns>
public static Icon GetDefaultDirectoryIcon(IconSize size, FolderType folderType)
{
var flags = ShgfiIcon | ShgfiUsefileattributes;
if (FolderType.Open == folderType)
{
flags += ShgfiOpenicon;
}
if (IconSize.Small == size)
{
flags += ShgfiSmallicon;
}
else
{
flags += ShgfiLargeicon;
}
var shfi = new Structs.Shfileinfo();
var res = DllImports.SHGetFileInfo(@"C:\Windows", FileAttributeDirectory, out shfi, (uint) Marshal.SizeOf(shfi), flags);
if (res == IntPtr.Zero)
{
throw Marshal.GetExceptionForHR(Marshal.GetHRForLastWin32Error());
}
Icon.FromHandle(shfi.hIcon);
var icon = (Icon) Icon.FromHandle(shfi.hIcon).Clone();
DllImports.DestroyIcon(shfi.hIcon);
return icon;
}
示例14: GetFileIcon
/// <summary>
/// Returns an icon for a given file - indicated by the name parameter</summary>
/// <param name="name">Pathname for file</param>
/// <param name="size">Large or small icon</param>
/// <param name="linkOverlay">Whether to include the link icon</param>
/// <returns>Icon</returns>
public static Icon GetFileIcon(string name, IconSize size, bool linkOverlay)
{
Shell32.SHFILEINFO shfi = new Shell32.SHFILEINFO();
uint flags = Shell32.SHGFI_ICON | Shell32.SHGFI_USEFILEATTRIBUTES;
if (linkOverlay) flags += Shell32.SHGFI_LINKOVERLAY;
// Check the size specified for return.
if (IconSize.Small == size)
{
flags += Shell32.SHGFI_SMALLICON;
}
else
{
flags += Shell32.SHGFI_LARGEICON;
}
Shell32.SHGetFileInfo(name,
Shell32.FILE_ATTRIBUTE_NORMAL,
ref shfi,
(uint)System.Runtime.InteropServices.Marshal.SizeOf(shfi),
flags);
// Copy (clone) the returned icon to a new object, thus allowing us to clean-up properly
Icon icon = (Icon)Icon.FromHandle(shfi.hIcon).Clone();
User32.DestroyIcon(shfi.hIcon); // Cleanup
return icon;
}
示例15: GetFolderIcon
public static System.Drawing.Icon GetFolderIcon(string name, IconSize size, FolderType folderType)
{
Shell32.SHFILEINFO shfi = new Shell32.SHFILEINFO();
uint flags = Shell32.SHGFI_ICON | Shell32.SHGFI_USEFILEATTRIBUTES;
if (FolderType.Open == folderType)
{
flags += Shell32.SHGFI_OPENICON;
}
//if (true == linkOverlay) flags += Shell32.SHGFI_LINKOVERLAY;
/* Check the size specified for return. */
if (IconSize.Small == size)
{
flags += Shell32.SHGFI_SMALLICON;
}
else
{
flags += Shell32.SHGFI_LARGEICON;
}
Shell32.SHGetFileInfo(name,
Shell32.FILE_ATTRIBUTE_DIRECTORY,
ref shfi,
(uint)System.Runtime.InteropServices.Marshal.SizeOf(shfi),
flags);
// Copy (clone) the returned icon to a new object, thus allowing us to clean-up properly
System.Drawing.Icon icon = (System.Drawing.Icon)System.Drawing.Icon.FromHandle(shfi.hIcon).Clone();
User32.DestroyIcon(shfi.hIcon); // Cleanup
return icon;
}