110,537
社区成员
发帖
与我相关
我的任务
分享
private void LoadImage()
{
Label lb1 = new Label();
lb1.Text = "正在读取图片";
lb1.Location = new Point(100, 100);
this.Controls.Add(lb1);
PictureBox pb = new PictureBox();
this.Controls.Add(pb);
Thread th = new Thread(() =>
{
int tick = 0;
while (tick < 100) //尝试100次
{
if (File.Exists("you file Path"))
{
this.Invoke(new MethodInvoker(() =>
{
Image img = Image.FromFile("path");
pb.Image = img;
}));
break;
}
Thread.Sleep(100);
}
this.Invoke(new MethodInvoker(() =>
{
lb1.Text = "读取文件失败";
}));
});
th.IsBackground = true;
th.Start();
}
FileSystemWatcher fileWatcher = new FileSystemWatcher
{
Filter = filename,
Path = path,
};
fileWatcher.Created += (sender, e) =>
{
//....
};
fileWatcher.EnableRaisingEvents = true;
private void ExportPicture_Load(Object sender,EventArgs e)
{
ExportPicture_Load(null,null)
}