private void flowLayoutPanel2_DragDrop(object sender, DragEventArgs e) { try { //拖曳檔案是否存在 if (File.Exists(fileName)) { Bitmap img = new Bitmap(fileName); photox pic = new photox(); //將圖片顯示在pictureBox1 pic.Image = img; pic.Width = 100; pic.Height = 80; pic.BorderStyle = BorderStyle.Fixed3D; pic.SizeMode = PictureBoxSizeMode.StretchImage; pic.Padding = new Padding(5); this.flowLayoutPanel2.Controls.Add(pic); pic.SizeMode = PictureBoxSizeMode.StretchImage; pic.Click += Pic_Click; pic.MouseEnter += Pic_MouseEnter; pic.MouseLeave += Pic_MouseLeave; pho.Add(pic); pic.px++; } } catch (Exception ex) { MessageBox.Show("不是有效的圖檔格式"); } }
private void label4_Click(object sender, EventArgs e) { flowLayoutPanel1.Controls.Clear(); MyAlbumEntities3 ae3 = new MyAlbumEntities3(); var alQuery = from al in ae3.Photos where al.Description == "Paris" select al.Picture; foreach (byte[] phoo in alQuery) { MemoryStream mym = new MemoryStream(phoo, 0, phoo.Length); photox pic = new photox(); pic.Image = Image.FromStream(mym); pic.Width = 100; pic.Height = 80; pic.BorderStyle = BorderStyle.Fixed3D; pic.SizeMode = PictureBoxSizeMode.StretchImage; pic.Padding = new Padding(5); this.flowLayoutPanel1.Controls.Add(pic); pic.Click += Pic_Click; pic.MouseEnter += Pic_MouseEnter; pic.MouseLeave += Pic_MouseLeave; pho.Add(pic); pic.px = phoo.Length - 1; } }
private void button1_Click(object sender, EventArgs e) { if (this.openFileDialog1.ShowDialog() == DialogResult.OK) { string[] filenames = this.openFileDialog1.FileNames; for (int i = 0; i <= filenames.Length - 1; i++) { photox pic = new photox(); pic.Width = 100; pic.Height = 80; pic.BorderStyle = BorderStyle.Fixed3D; pic.Image = Image.FromFile(filenames[i]); pic.SizeMode = PictureBoxSizeMode.StretchImage; pic.Padding = new Padding(5); pic.Click += Pic_Click; pic.MouseEnter += Pic_MouseEnter; pic.MouseLeave += Pic_MouseLeave; pic.px = i; pho.Add(pic); this.flowLayoutPanel2.Controls.Add(pic); } } }