-3

I've got 2 Panels. Both panels load a given time. Now i want to add some animation on both panels

// animation start of panel1
panel1.show();

// animation start of panel2
panel2.show();

After panel1 finished it's animation, the 2nd panel animation starts. Soo now I want to animate both panels the same time.

I think multithreading can do that. Can you show me how this could work in my particular in my case?

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;
} 
J...
  • 30,968
  • 6
  • 66
  • 143
Hiral Bhimani
  • 120
  • 4
  • 13
  • 3
    Please show your animation code and where it is implemented. Explicit multithreading may not be necessary depending on the complexity and nature of the animation. – J... Feb 27 '13 at 14:39
  • what version of .Net you using? 4.0 has significant upgrades in threading management if your using this. – Liam Feb 27 '13 at 14:39
  • 3
    Considering that both animations will be done on the UI thread, I don't think that Parallel will help you in this case. – Cristian Chereches Feb 27 '13 at 14:40
  • here is my code http://db.tt/jHl5pn2F – Hiral Bhimani Feb 27 '13 at 14:47
  • @HiralBhimani - I've added your code to the post. It is good practice to do this and not to add it as a link to dropbox, pastebin, etc. – J... Feb 27 '13 at 18:30
  • Also, looking at your code now, this is specifically about a call to `AnimateWindow` - see here for your answer (voting to close as duplicate) : http://stackoverflow.com/questions/11147086/how-can-i-use-the-animatewindow-function-on-a-separate-thread – J... Feb 27 '13 at 18:48
  • Specifically, here, the answer is that this is not possible. It is a limitation of the `AnimateWindow` function. To get both controls animating simultaneously you would need to change your approach. – J... Feb 27 '13 at 18:50
  • thnxxxx....i change my form and reduce the controls...so now everything work fine – Hiral Bhimani Mar 07 '13 at 14:23

1 Answers1

-2

I suggest using BackgroundWorker or Timer component.

semao
  • 1,757
  • 12
  • 12
  • but how to apply in My case – Hiral Bhimani Feb 27 '13 at 14:51
  • Neither of these will work with the call to `AnimateWindow` since a background thread or timer would eventually end up marshalling the call to the UI thread which would, by design, have to run the calls in sequence. `AnimateWindow` cannot be parallelized in any sane way within a single control. – J... Feb 28 '13 at 14:11