本文整理汇总了C#中System.Windows.Forms.PictureBox.BeginInvoke方法的典型用法代码示例。如果您正苦于以下问题:C# PictureBox.BeginInvoke方法的具体用法?C# PictureBox.BeginInvoke怎么用?C# PictureBox.BeginInvoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.PictureBox
的用法示例。
在下文中一共展示了PictureBox.BeginInvoke方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: updater
private void updater(PictureBox pb, Data d)
{
if (pb.InvokeRequired)
{
pb.BeginInvoke(new SetImageCallback(updater), pb, d);
}
else
{
pb.Image = d.Img;
lbProgress.Text = (!d.Progress.Equals("Done!")) ? d.Progress + "/" + 100 : d.Progress;
lbPack.Text = d.Pack.X + "-" + d.Pack.Y;
lbDirSize.Text = (size / 1024) + "KB" + " (" + size + ")";
btnStart.Enabled = d.BtnEnable;
btnStart.Text = d.BtnText;
}
}
示例2: setNewFrame
private void setNewFrame(PictureBox canvas, Bitmap frame)
{
// Invoke is required when updating a control on the GUI thread.
if (canvas.InvokeRequired)
{
canvas.BeginInvoke(new MethodInvoker(delegate()
{
setFrame(canvas, frame);
}));
}
else
{
setFrame(canvas, frame);
}
}
示例3: RunLoading
private static void RunLoading(string url, string path, PictureBox picture, TextBox box = null)
{
new Thread(() =>
{
Timer loadingTimer = null;
if (!BstPicLoader.LoadingTimers.ContainsKey(picture))
{
// 更新图片成读取状态,如果Dictionary里已经有这个PictureBox的Timer了,说明loading图已经加载了
var loadingGif = new BstGifImage(BstManager.PathLoadingGif) { ReverseAtEnd = false };
loadingTimer = new Timer(50);
loadingTimer.Elapsed += (s, e) =>
{
MethodInvoker loadingAction = () =>
{
picture.Image = loadingGif.GetNextFrame();
};
try
{
picture.BeginInvoke(loadingAction);
}
catch (InvalidOperationException ex)
{
BstLogger.Instance.Log(ex.ToString());
// 因为我们可能会在GUI_Picture的UI中的PictureBox里显示loading动态图
// 而上述的窗口可能在关闭后被销毁,这里我们需要处理窗口被销毁后的错误
// 这时候Timer应该在Dictionary里注册过了
if (BstPicLoader.LoadingTimers.ContainsKey(picture))
{
var timer = BstPicLoader.LoadingTimers[picture];
timer.Enabled = false;
BstPicLoader.LoadingTimers.Remove(picture);
timer.Dispose();
}
}
};
BstPicLoader.LoadingTimers.Add(picture, loadingTimer);
loadingTimer.Enabled = true;
}
else
{
loadingTimer = BstPicLoader.LoadingTimers[picture];
}
// 检查是否有本地缓存
byte[] blob = null;
if (File.Exists(path))
{
// 本地缓存存在,直接读取
blob = BstManager.GetBytesFromFile(path);
}
else
{
// 下载图片
blob = BstManager.DownloadImageFile(url, path);
if (blob == null)
{
// 图片下载失败
BstManager.ShowMsgInTextBox(box, string.Format(BstI18NLoader.Instance.LoadI18NValue("BstPicLoader", "picDownloadFailed"), url));
// 停止动态图更新
loadingTimer.Enabled = false;
BstPicLoader.LoadingTimers.Remove(picture);
loadingTimer.Dispose();
// 更新下载失败icon
var errorIconBitmap = BstManager.ConvertByteToImage(BstManager.Instance.ErrorIconBytes);
MethodInvoker updateErrorAction = () => picture.Image = errorIconBitmap;
try
{
picture.BeginInvoke(updateErrorAction);
}
catch (Exception ex)
{
BstLogger.Instance.Log(ex.ToString());
}
return;
}
}
loadingTimer.Enabled = false; // 加载完成,停止动态loading图的更新
BstPicLoader.LoadingTimers.Remove(picture); // 加载完成,删除Dictionary里注册的Timer
loadingTimer.Dispose();
BstManager.ShowMsgInTextBox(box, string.Format(BstI18NLoader.Instance.LoadI18NValue("BstPicLoader", "picDownloadSucceed"), url));
// 转换成位图
var bitmap = BstManager.ConvertByteToImage(blob);
// 更新图片内容
MethodInvoker updateAction = () => picture.Image = bitmap;
try
{
picture.BeginInvoke(updateAction);
}
catch (Exception ex)
{
BstLogger.Instance.Log(ex.ToString());
}
}).Start();
}