Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
ResourceUtil.cs
Package: ProgressBar_src.rar [view]
Upload User: nnpulika
Upload Date: 2013-02-15
Package Size: 597k
Code Size: 6k
Category:
StatusBar
Development Platform:
C#
- using System;
- using System.IO;
- using System.Drawing;
- using System.Reflection;
- using System.Windows.Forms;
- using System.Resources;
- namespace UtilityLibrary.General
- {
- public class ResourceUtil
- {
- #region Methods
- public static Icon LoadIconStream(Type assemblyType, string iconName)
- {
- // Get the assembly that contains the bitmap resource
- Assembly myAssembly = Assembly.GetAssembly(assemblyType);
- // Get the resource stream containing the images
- Stream iconStream = myAssembly.GetManifestResourceStream(iconName);
- // Load the Icon from the stream
- return new Icon(iconStream);
- }
- public static Icon LoadIconStream(Type assemblyType, string iconName, Size iconSize)
- {
- // Load the entire Icon requested (may include several different Icon sizes)
- Icon rawIcon = LoadIconStream(assemblyType, iconName);
- // Create and return a new Icon that only contains the requested size
- return new Icon(rawIcon, iconSize);
- }
- public static Bitmap LoadBitmapStream(Type assemblyType, string imageName)
- {
- return LoadBitmapStream(assemblyType, imageName, false, new Point(0,0));
- }
- public static Bitmap LoadBitmapStream(Type assemblyType, string imageName, Point transparentPixel)
- {
- return LoadBitmapStream(assemblyType, imageName, true, transparentPixel);
- }
- public static ImageList LoadImageListStream(Type assemblyType,
- string imageName,
- Size imageSize)
- {
- return LoadImageListStream(assemblyType, imageName, imageSize, false, new Point(0,0));
- }
- public static ImageList LoadImageListStream(Type assemblyType,
- string imageName,
- Size imageSize,
- Point transparentPixel)
- {
- return LoadImageListStream(assemblyType, imageName, imageSize, true, transparentPixel);
- }
- public static ImageList LoadImageListStream(Type assemblyType,
- string imageName,
- Size imageSize,
- bool makeTransparent,
- Point transparentPixel)
- {
- // Create storage for bitmap strip
- ImageList images = new ImageList();
- // Define the size of images we supply
- images.ImageSize = imageSize;
- // Get the assembly that contains the bitmap resource
- Assembly myAssembly = Assembly.GetAssembly(assemblyType);
- // Get the resource stream containing the images
- Stream imageStream = myAssembly.GetManifestResourceStream(imageName);
- // Load the bitmap strip from resource
- Bitmap pics = new Bitmap(imageStream);
- if (makeTransparent)
- {
- Color backColor = pics.GetPixel(transparentPixel.X, transparentPixel.Y);
- // Make backColor transparent for Bitmap
- pics.MakeTransparent(backColor);
- }
- // Load them all !
- images.Images.AddStrip(pics);
- return images;
- }
- // The difference between the "LoadXStream" and "LoadXResource" functions is that
- // the load stream functions will load a embedded resource -- a file that you choose
- // to "embed as resource" while the load resource functions work with resource files
- // that have structure (.resX and .resources) and thus can hold several different
- // resource items.
- public static Icon LoadIconResource(Type assemblyType, string resourceHolder, string imageName)
- {
- // Get the assembly that contains the bitmap resource
- Assembly thisAssembly = Assembly.GetAssembly(assemblyType);
- ResourceManager rm = new ResourceManager(resourceHolder, thisAssembly);
- Icon icon = (Icon)rm.GetObject(imageName);
- return icon;
- }
- public static Bitmap LoadBitmapResource(Type assemblyType, string resourceHolder, string imageName)
- {
- // Get the assembly that contains the bitmap resource
- Assembly thisAssembly = Assembly.GetAssembly(assemblyType);
- ResourceManager rm = new ResourceManager(resourceHolder, thisAssembly);
- Bitmap bitmap = (Bitmap)rm.GetObject(imageName);
- return bitmap;
- }
- public static ImageList LoadImageListResource(Type assemblyType, string resourceHolder,
- string imageName, Size imageSize)
- {
- return LoadImageListResource(assemblyType, resourceHolder, imageName, imageSize, false, new Point(0,0));
- }
- public static ImageList LoadImageListResource(Type assemblyType, string resourceHolder,
- string imageName,
- Size imageSize,
- bool makeTransparent,
- Point transparentPixel)
- {
- // Create storage for bitmap strip
- ImageList images = new ImageList();
- // Define the size of images we supply
- images.ImageSize = imageSize;
- // Get the assembly that contains the bitmap resource
- Assembly thisAssembly = Assembly.GetAssembly(assemblyType);
- ResourceManager rm = new ResourceManager(resourceHolder, thisAssembly);
- Bitmap pics = (Bitmap)rm.GetObject(imageName);
- if (makeTransparent)
- {
- Color backColor = pics.GetPixel(transparentPixel.X, transparentPixel.Y);
- // Make backColor transparent for Bitmap
- pics.MakeTransparent(backColor);
- }
- // Load the image
- images.Images.AddStrip(pics);
- return images;
- }
- #endregion
- #region Implementation
- protected static Bitmap LoadBitmapStream(Type assemblyType, string imageName,
- bool makeTransparent, Point transparentPixel)
- {
- // Get the assembly that contains the bitmap resource
- Assembly myAssembly = Assembly.GetAssembly(assemblyType);
- // Get the resource stream containing the images
- Stream imageStream = myAssembly.GetManifestResourceStream(imageName);
- // Load the bitmap from stream
- Bitmap image = new Bitmap(imageStream);
- if (makeTransparent)
- {
- Color backColor = image.GetPixel(transparentPixel.X, transparentPixel.Y);
- // Make backColor transparent for Bitmap
- image.MakeTransparent(backColor);
- }
- return image;
- }
- #endregion
- }
- }