本文整理匯總了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();
}