我正在从文件夹中获取图像并使用以下代码在图片框中显示它们
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 ?
}