次のコードを使用して、フォルダーから画像を取得し、画像ボックスに表示しています
protected void image()
{
string str = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().Location);
string path = str + "\\images\\";
//Our target folder; change this to the folder to get the images from
string GivenFolder = str + "\\images\\";
//Initialize a new List of type Image as ImagesInFolder
List<System.Drawing.Image> ImagesInFolder = new List<System.Drawing.Image>();
// Initialize a new string of name JPEGImages for every string in the
// string array returned from the given folder as files
foreach (string JPEGImages in Directory.GetFiles(GivenFolder, "*.jpg"))
{
//Add the Image gathered to the List collection
ImagesInFolder.Add(System.Drawing.Image.FromFile(JPEGImages));
}
int x = 0; //Initialize X as int of value 0
int y = 0; //Initialize Y as int of value 0
// Initialize i as an int of value 0, continue if i is less than ImagesInFolder
// count. Increment i by 1 each time you continue
for (int i = 0; i < ImagesInFolder.Count; i++)
{
PictureBox I = new PictureBox(); //Initialize a new PictureBox of name I
I.Location = new System.Drawing.Point(x, y); //Set the PictureBox location to x,y
x += 50; //Sort horizontally; Increment x by 50
//y += 50; //Sort vertically; Increment y by 50
//Set the Image property of I to i in ImagesInFolder as index
I.Image = ImagesInFolder[i];
//Set the PictureBox Size property to 50,50
I.Size = new System.Drawing.Size(80, 80);
//Stretch the image; maximum width and height are 50,50
I.SizeMode = PictureBoxSizeMode.StretchImage;
flowLayoutPanel1.Controls.Add(I); //Add the PictureBox to the FlowLayoutPanel
}
}
コードから画像ボックスを作成しているので、その特定の画像ボックスの特定picture box's image
を開くことができるように関数を書くにはどうすればよいですか?プロパティウィンドウからイベントを選択することはできません。コード、このようなものclick event
winform
private void PictureboxClick_event()
{
FormtoOpen f=new FormtoOpen();
f.show();
//.....how that particular image will be displayed ?
}