我想做任务并行在c# .net Winforms应用程序
本文关键字:net Winforms 应用程序 并行 任务 | 更新日期: 2023-09-27 18:01:18
我有2个Panels
。两个面板加载给定的时间。现在我想在两个面板上都添加一些动画
// animation start of panel1
panel1.show();
// animation start of panel2
panel2.show();
当panel1
完成它的动画后,第二个面板动画开始。所以现在我想同时为两个面板动画。
public static class Util {
public enum Effect { Roll, Slide, Center, Blend }
public static void Animate(Control ctl, Effect effect, int msec, int angle)
{
int flags = effmap[(int)effect];
if (ctl.Visible) {flags |= 0x10000; angle += 180;}
else {
if (ctl.TopLevelControl == ctl) flags |= 0x20000;
else if (effect == Effect.Blend) throw new ArgumentException();
}
flags |= dirmap[(angle % 360) / 45];
bool ok = AnimateWindow(ctl.Handle, msec, flags);
if (!ok) throw new Exception("Animation failed");
ctl.Visible = !ctl.Visible;
}
private static int[] dirmap = { 1, 5, 4, 6, 2, 10, 8, 9 };
private static int[] effmap = { 0, 0x40000, 0x10, 0x80000 };
[DllImport("user32.dll")] private static extern bool
AnimateWindow(IntPtr handle, int msec, int flags);
}
private void Form1_Load(object sender, EventArgs e) {
Util.Animate(radPanel1, Util.Effect.Slide, 700, 360);
radPanel1.Show();
expandablePanel1.Expanded = true;
}
我建议使用BackgroundWorker或Timer组件。