Introduction
In VB6 we can create many Controls (Label, TextBox, Button, PictureBox, …etc.) as
Array, but Visual Studio .NET not support this work. I try to create Array of PictureBox
controls in this article, I shall send another article at next time about create Array of
Labels and Buttons.
Background
My article has two Forms, name of one is (frmThumb) and name of other is (frmView).
With the first form you can load all images in any folder as Thumbnail by click the
button (Load images). Then when Click any image You can view this image
with own size on the form (frmView).
The form (frmThumb) has:
one Panel control (BackPanel) to hold images,
Progress control (MyProgress ) work while images are loading,
Two buttons: one (btnLoad) to load images, other (btnExit) to exit Application.
The form (frmView) has:
One pictureBox control (imgDisplay) to view the image which You click, I let the
property SizeMode = AutoSize,
label (lblImageName) to view the name and full path of the image,
button (btnClose) to close the form and return to the form (frmThumb).
Using the code
The important code is the code to create the Array:
//
// Function to add PictureBox controls, You can determine number of controls
//
private void AddControls(int cNumber)
{
// assign number of controls (cNumber):
imgArray = new System.Windows.Forms.PictureBox[cNumber];
for (int i = 0; i < cNumber; i++)
{
// Initialize one variable
imgArray[i] = new System.Windows.Forms.PictureBox();
}
}
I create Click Image Event :
//
// The function ClickImage:
//
private void ClickImage(Object sender, System.EventArgs e)
{
- 1
- 2
- 3
- 4
- 5
- 6
前往页