Visual C++ .Net Controls: Image Lists |
|
Introduction |
An image list is a group of images intended to solve a common issue. Such images can be used to represent buttons of a toolbar or items of list-based control, etc. |
#using <mscorlib.dll> #using <System.dll> #using <System.Windows.Forms.dll> using namespace System; using namespace System::Windows::Forms; __gc class SimpleForm : public Form { public: SimpleForm(); }; SimpleForm::SimpleForm() { // The caption of the form this->Text = S"Image Lists and Nothing Else"; } int __stdcall WinMain() { SimpleForm *SF = new SimpleForm(); Application::Run(SF); return 0; } |
Creating an Image List |
To create an image list, you can use the ImageList control. Each image is added to a list. Once the list is created, the group is treated as a pseudo-control but usually, each image can still be accessed as its own object. |
The following exercise only shows how to create an image list. It doesn't actually use the image list. |
#using <mscorlib.dll> #using <System.dll> #using <System.Drawing.dll> #using <System.Windows.Forms.dll> using namespace System; using namespace System::Drawing; using namespace System::Windows::Forms; __gc class SimpleForm : public Form { public: SimpleForm(); private: // Declare a pointer to the ImageList class ImageList *icoImages; }; SimpleForm::SimpleForm() { // The caption of the form this->Text = S"Image Lists and Nothing Else"; // Use the declared pointer to initialize the ImageList object icoImages = new ImageList; // Add each image, as a bitmap or an icon, to the list of images icoImages->Images->Add(Image::FromFile("Belgium.bmp")); icoImages->Images->Add(Image::FromFile("Diamond.bmp")); icoImages->Images->Add(Image::FromFile("Feather.bmp")); } int __stdcall WinMain() { SimpleForm *SF = new SimpleForm(); Application::Run(SF); return 0; } |
|
||
Home | Copyright © 2002 FunctionX, Inc. | |
|