Animation in Winform

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?Umljaw==?=

    Animation in Winform

    I have a form with a button control. When button is clicked; it run a process
    which take a bit of time to complete the process.

    When this button is clicked; I want to animate an image on the screen while
    this process is in progerss. It is the same as displaying a progress bar butI
    want to display animated image.
    How do I do it in vs2005? My code is similiar to the following:

    public partial class Form1 : Form
    {
    private Bitmap img;
    private string sFilename = "C:\\MyGif.gif" ;
    PictureBox imgPhoto = new PictureBox();

    public Form1()
    {
    InitializeCompo nent();

    img = new Bitmap(sFilenam e);
    }

    private void button1_Click(o bject sender, EventArgs e)
    {
    ProgressAnimati on();
    MyLongRunningPr ocess()

    }

    private void MyLongRunningPr ocess()
    {
    Retrieve20Milli onRecordsFromDa tabase();
    }

    private void Retrieve20Milli onRecordsFromDa tabase()
    {
    DoThis();
    DoThat();
    ---- etc.
    ---- etc.
    }

    private void ProgressAnimati on()
    {
    imgPhoto.Border Style = System.Windows. Forms.BorderSty le.Fixed3D;
    imgPhoto.Height = 30;
    imgPhoto.Width = 100;
    imgPhoto.Left = 10;
    imgPhoto.Top = 20;
    imgPhoto.BackCo lor = Color.Red;
    Controls.Add(im gPhoto);
    imgPhoto.Image = img;
    }
    }
  • Ignacio Machin ( .NET/ C# MVP )

    #2
    Re: Animation in Winform

    On Sep 26, 2:23 pm, Rick <R...@discussio ns.microsoft.co mwrote:
    I have a form with a button control. When button is clicked; it run a process
    which take a bit of time to complete the process.
    >
    When this button is clicked; I want to animate an image on the screen while
    this process is in progerss. It is the same as displaying a progress bar butI
    want to display animated image.
    How do I do it in vs2005? My code is similiar to the following:
    Two things, you have to run the query in another thread. This will
    free the UI thread to execute your animation.
    With that said, all you need is decide how to do the animation. The
    basic one is a ProgressBar but you can use a more refined nethod.
    I did a search for c# windows form animated gif in google and found
    several examples.

    Remember taht when finished you need to indicate it to the UI thread
    by using Control.Invoke

    Comment

    • =?Utf-8?B?Umljaw==?=

      #3
      RE: Animation in Winform

      The sample code I provided will display the image without animation.

      "Rick" wrote:
      I have a form with a button control. When button is clicked; it run a process
      which take a bit of time to complete the process.
      >
      When this button is clicked; I want to animate an image on the screen while
      this process is in progerss. It is the same as displaying a progress bar butI
      want to display animated image.
      How do I do it in vs2005? My code is similiar to the following:
      >
      public partial class Form1 : Form
      {
      private Bitmap img;
      private string sFilename = "C:\\MyGif.gif" ;
      PictureBox imgPhoto = new PictureBox();
      >
      public Form1()
      {
      InitializeCompo nent();
      >
      img = new Bitmap(sFilenam e);
      }
      >
      private void button1_Click(o bject sender, EventArgs e)
      {
      ProgressAnimati on();
      MyLongRunningPr ocess()
      >
      }
      >
      private void MyLongRunningPr ocess()
      {
      Retrieve20Milli onRecordsFromDa tabase();
      }
      >
      private void Retrieve20Milli onRecordsFromDa tabase()
      {
      DoThis();
      DoThat();
      ---- etc.
      ---- etc.
      }
      >
      private void ProgressAnimati on()
      {
      imgPhoto.Border Style = System.Windows. Forms.BorderSty le.Fixed3D;
      imgPhoto.Height = 30;
      imgPhoto.Width = 100;
      imgPhoto.Left = 10;
      imgPhoto.Top = 20;
      imgPhoto.BackCo lor = Color.Red;
      Controls.Add(im gPhoto);
      imgPhoto.Image = img;
      }
      }

      Comment

      • =?Utf-8?B?Umljaw==?=

        #4
        Re: Animation in Winform

        Could you please provide me some sample code?

        "Ignacio Machin ( .NET/ C# MVP )" wrote:
        On Sep 26, 2:23 pm, Rick <R...@discussio ns.microsoft.co mwrote:
        I have a form with a button control. When button is clicked; it run a process
        which take a bit of time to complete the process.

        When this button is clicked; I want to animate an image on the screen while
        this process is in progerss. It is the same as displaying a progress bar butI
        want to display animated image.
        How do I do it in vs2005? My code is similiar to the following:
        >
        Two things, you have to run the query in another thread. This will
        free the UI thread to execute your animation.
        With that said, all you need is decide how to do the animation. The
        basic one is a ProgressBar but you can use a more refined nethod.
        I did a search for c# windows form animated gif in google and found
        several examples.
        >
        Remember taht when finished you need to indicate it to the UI thread
        by using Control.Invoke
        >

        Comment

        • =?Utf-8?B?Umljaw==?=

          #5
          Re: Animation in Winform

          I googled and found some samples; trying to get that to work for me.

          "Rick" wrote:
          Could you please provide me some sample code?
          >
          "Ignacio Machin ( .NET/ C# MVP )" wrote:
          >
          On Sep 26, 2:23 pm, Rick <R...@discussio ns.microsoft.co mwrote:
          I have a form with a button control. When button is clicked; it run a process
          which take a bit of time to complete the process.
          >
          When this button is clicked; I want to animate an image on the screen while
          this process is in progerss. It is the same as displaying a progress bar butI
          want to display animated image.
          How do I do it in vs2005? My code is similiar to the following:
          Two things, you have to run the query in another thread. This will
          free the UI thread to execute your animation.
          With that said, all you need is decide how to do the animation. The
          basic one is a ProgressBar but you can use a more refined nethod.
          I did a search for c# windows form animated gif in google and found
          several examples.

          Remember taht when finished you need to indicate it to the UI thread
          by using Control.Invoke

          Comment

          Working...