System.IO and Embedded Images.
Using Images with .net controls is really easy. The choice you need to make, is
whether the image will be embedded into the application or whether the image will
be a local resource (in a file on the users hard drive).
Images from files or on the users local hard drive has the advantage of a quick
and easy image change without needing to re-install any software. But of course,
if the user deletes, moves or renames the image files for what ever reason, the
application will look incomplete or could crash due to lack of error checking.
Images used from within your application (Embedded Resource) offer protection of
accidental deletion, renaming and moving. Images and other objects used by method
of Embedded resources also offer a application performance increase over those using
File methods. The only single disadvantage to using Embedded resources is if for
what ever reason you need to change an image, you will need to reinstall the application.

Assigning images to Controls that support Images.
Using the Image.FromFile method.
System.IO.FileInfo fileInfo = new System.IO.FileInfo(@"c:\Icons\helloworld.gif");
//Check if the file exists. If the file exists, assign the image to the control.
if (fileInfo.Exists) { this.button1.Image = Image.FromFile(@"c:\Icons\helloworld.gif");
}
Using an Image.FromStream Method.
Here we are going to assign an Image to a checkBox control, but this time
the image will be an embedded resource file.
System.IO.Stream imageStream = this.GetType().Assembly.GetManifestResourceStream("Controls.002-folder_add.png");
checkBox1.Image = Image.FromStream(imageStream);
Here the "Controls.002-folder_add.png" breaks down to 2 parts.
Firstly the "Controls" is the name of my NameSpace. Secondly the 002-folder_add.png
is the name of my Imag file.
Using an Image from the Global Resource File.
checkBox1.Image = global::Controls.Properties.Resources._412_forward;
Using an Image from an Image List.
Here we need to assign an ImageList to the controls ImageList property. Then we
will assign an index value from the ImageList.
button1.ImageList = this.imageList1;
button1.ImageIndex = 0;
Infragistics Controls.
Infragistics Controls offer all the same Image methods as in the Windows Controls.
You might find some property name changes. Below are some examples:
Using an Image.FromFile Method.
System.IO.FileInfo fileInfo = new System.IO.FileInfo(@"c:\Icons\helloworld.gif");
if (fileInfo.Exists) { this.ultraButton1.Appearance.Image = Image.FromFile(@"c:\Icons\helloworld.gif");
}
Using an Image from an ImageList.
First we assign an ImageList to the ImageList property, then we assign an index
value to the image property.
this.ultraButton1.ImageList = this.imageList1;
this.ultraButton1.Appearance.Image = 3;
Using an Image from an Embedded resource via a Stream.
System.IO.Stream imageStream = this.GetType().Assembly.GetManifestResourceStream("Controls.1.gif");
this.ultraButton1.Appearance.Image = Image.FromStream(imageStream);
|