The below code is just abstract just to show simple use of delegate
using System.Data;
using System.IO;
using System.Drawing;
using System.Text;
using System.Threading;
public partial class ImageView : Form{
Mydel a;
public delegate void Mydel(PictureBox p);
public ImageView(){
InitializeComponent();
}
private void ImageView_Load(object sender, EventArgs e){
a = new Mydel(Add);
Thread t = new Thread(load);
t.Start();
}
public void load(){
DirectoryInfo dinfo = new DirectoryInfo(@"F:\Mypics");
if (Image.FromFile(finfo[i].FullName) != null){ PictureBox p = new PictureBox();
Controls[Controls.IndexOf(panel1)].Invoke(a, obj);
if (x > this.Width-100){ y += 100;
}
} } public void Add(PictureBox p) { panel1.Controls.Add(p); } } }
FileInfo[] finfo = dinfo.GetFiles();
Graphics g = panel1.CreateGraphics();
int x = 20;
int y = 20;
for (int i = 0; i
p.Image = Image.FromFile(finfo[i].FullName);
p.SizeMode = PictureBoxSizeMode.StretchImage;
p.Left = x;
p.Top = y;
p.ImageLocation = finfo[i].FullName;
p.Width = 140;
p.Height = 90;
Object[] obj = new Object[1];
obj[0] = p;
x += 150;
x = 20;
}
if (i > 35)
break;
No comments:
Post a Comment