This tutorial will teach you how to make an easily reusable function that will load any icon file into a picture box controls in Visual CSharp .Net.
Loading Icons into Picture Box
To be able to create the icon loading void you will need to add two references before your namespace. These references are System Drawing and System IO. Add them like so:
using System.IO;
using System.Drawing;
Now, that you have the proper references, create a public void called LoadIcon with a PictureBox parameter called PicBox and a String parameter called IconPath. Use this source code to make the void:
public void LoadIcon(PictureBox PicBox, String IconPath)
{
//Initialize temporary images and icons
System.Drawing.Image icoIMG = null;
System.Drawing.Icon tmpICO = new System.Drawing.Icon(IconPath);
//Create an Imagelist to Hold the Icon
ImageList tmpImgLst = new ImageList();
tmpImgLst.Images.Add(tmpICO);
icoIMG = tmpImgLst.Images[0];
PicBox.Image = icoIMG;
}
The function that you created will load the specified icon file into an image list and then load the image from the image list into the picture box. Thus allowing you to easily load icon files into a Picture Box control.
Conclusion
With the proper function all you need to do is call the LoadIcon method and supply your desired picture box as the first parameter and the string path to your icon as the second parameter. Here is an example:
LoadIcon(picIcon, "C:\\My Images\\smiley.ico");
This will load the icon file, C:\My Images\smiley.ico, into the picture box, picIcon.
Published by James Cloud
I like to program and do basically anything that has to do with technology and computers. View profile
Picture Frame Decor for Plain Wooden HeadboardsLooking for a nicer headboard but want to spare the expense? Take your headboard from plain to fabulous by using a simple picture frame or two.- Bosch AXXIS Plus 3.4 Cu. Ft. Front Load Washer Review, Model: WAS24460UCThe Bosch AXXIS Plus 3.4 Cu. Ft. Front Load Washing Machine, Model: WAS24460UC has been designed to properly clean even the most difficult clothing, and with the high efficiency design, you will not only save money bu...
Drive Image XML - Free Computer ToolA review of the free tool called Drive Image XML. It is a very useful tool for backups, restores, and many other things.
- Shabby Chic Picture Frame Shadow Box DIY Project
- Arts and Crafts Ideas Using Picture Frames: How-To Guide
- Turner Classic Movies to Feature Marathon of Best Picture Oscar Winners in February
- How to Create a Child's Craft Box: Crafts for Self Motivated Kids
- Secret Picture Boxes: Crafts for Creative Kids
- American Image Salon and Spa in St. Louis, Missouri
- Real Estate Specializing: Triple Net Lease Property



