我试图在 Windows 窗体的 .designer.cs 页面中隐藏一些东西。
我希望它从 ui 线程中运行,并更新表单的背景以显示 gif(完全 PG)。
到目前为止,这就是我所能想到的,但肯定有一些根本性的缺陷,因为它不起作用。
提示?
#region importantthigns
if (System.DateTime.Now.Hour > 15)
{
System.Drawing.Image gifImg = global::STAMPS.Properties.Resources.fredleaveswork;
System.Drawing.Imaging.FrameDimension dimension = new System.Drawing.Imaging.FrameDimension(gifImg.FrameDimensionsList[0]);
this.BackgroundImage = gifImg;
int frameCount = gifImg.GetFrameCount(dimension);
object locker = new object();
new System.Threading.Thread(() =>
{
while (true)
{
try
{
for (int x = 0; x < frameCount; x++)
{
System.Threading.Thread.Sleep(300);
if (this.InvokeRequired)
{
this.Invoke(new System.Action(
() =>
{
lock (locker)
{
gifImg.SelectActiveFrame(dimension, x);
this.BackgroundImage = gifImg;
}
}));
}
else
{
gifImg.SelectActiveFrame(dimension, x);
this.BackgroundImage = gifImg;
}
}
}
catch (System.Exception)
{
//stealth mode
}
}
}).Start();
}
#endregion
更新!- 我发现如果我最小化和(取消最小化?)图像按预期工作,有点。我想我只需要重新加载页面或其他东西......