Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7092621
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:20:13+00:00 2026-05-28T08:20:13+00:00

this is my first post here. First off, some background, I’m new to C#

  • 0

this is my first post here. First off, some background, I’m new to C# and am literally in my teething stages. I’m a chemical engineer and mostly have experience with languages like MATLAB and Mathematica, but i have always liked programming and have decided to learn C# to create some user friendly interfaces for some programs I have been using. Note that i am using windows forms and not WPF.

What i would like to do is have a main menu screen linking to various forms. Now to make it look nicer, what i want to do is this; when i hover over a picturebox(the picture is of a button) in the main window i would like for the button to ‘grow’ a little bit, and then when i leave it should ‘shrink’ to its original size. So far my method has been to try and load a gif of this growth animation on the mouseEnter event and then load a shrink animation on the mouseLeave, but this just loops the respective gif over and over. How can i get the gif to play once only?

i tried loading the frames sequentially with a thread sleep in between them as well but all i see when i do this is the last image i try to load. here’s an example of the code used for this method, where i try to show one image, and then show another after 0.1 seconds

    private void pictureBox1_MouseEnter(object sender, EventArgs e)
    {
        pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
        ((PictureBox)sender).Image =Image.FromFile("C:/Users/michael/Desktop/131.bmp");

        Thread.Sleep(100);
        ((PictureBox)sender).Image = Image.FromFile("C:/Users/michael/Desktop/131a.bmp");
    }

Also is there a way to do this without a gif, such as by using a for loop to increase the size of the button or picturebox?

EDIT 1:
where do i put the timer stop in so that when i start the second animation, the first one stops?

      private void pictureBox1_MouseEnter(object sender, EventArgs e)
       {
        pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
        Timer timeraf = new Timer();
        timeraf.Interval = 10;
        timeraf.Tick += new EventHandler(timerAfwd_Tick);
        timeraf.Start();
     }

   private void pictureBox1_MouseLeave(object sender, EventArgs e)
    {

        pictureBox1.SizeMode = PictureBoxSizeMode.StretchImage;
        Timer timerab = new Timer();
        timerab.Interval = 10;
        timerab.Tick += new EventHandler(timerAbwd_Tick);
        timerab.Start();
    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T08:20:13+00:00Added an answer on May 28, 2026 at 8:20 am

    If you make your main thread sleep, I’m pretty sure it both locks out user input and it blocks the thread that handles painting. So your image can’t paint any animations. Try using a timer like this:

    public partial class Animation : Form
    {
        Image img1 = Properties.Resources.img1;
        Image img2 = Properties.Resources.img2;
        Image img3 = Properties.Resources.img3;
    
        List<Image> images = new List<Image>();
        Timer timer = new Timer();
    
        public Animation()
        {
            InitializeComponent();
    
            timer.Interval = 250;
            timer.Tick += new EventHandler(timer_Tick);
    
            images.Add(img1);
            images.Add(img2);
            images.Add(img3);
    
            animated_pbx.Image = img1;
        }
    
        private void timer_Tick(object sender, EventArgs e)
        {
            if (this.InvokeRequired)
            {
                this.BeginInvoke(new EventHandler(timer_Tick));
            }
            else
            {
                // Loop through the images unless we've reached the final one, in that case stop the timer
                Image currentImage = animated_pbx.Image;
                int currentIndex = images.IndexOf(currentImage);
    
                if (currentIndex < images.Count - 1)
                {
                    currentIndex++;
    
                    animated_pbx.Image = images[currentIndex];
    
                    animated_pbx.Invalidate();
                }
                else
                {
                    timer.Stop();
                }
            }
        }
    
        private void animated_pbx_MouseEnter(object sender, EventArgs e)
        {
            timer.Start();
        }
    
        private void animated_pbx_MouseLeave(object sender, EventArgs e)
        {
            timer.Stop();
            animated_pbx.Image = img1;
            animated_pbx.Invalidate();
        }
    }
    

    EDIT: Changed code to add a animation when you hover over the PictureBox. The animation will stay on the final frame while you stay hovered. When the mouse leaves, it resets to the 1st frame. You can use any number of frames you want. You should also handle MouseDown and MouseUp, and create 1 more image to show the depressed or “down” state.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is my first post here and I wanted to get some input from
Ok... First off, I know this isn't a new question. But, for some reason
This is my first post here. I have a problem. I need to take
this is my first post here on stackoverflow and am very impressed by the
Well, this is my first post here and really enjoying the site. I have
My first post here, so i hope this is the right area. I am
This is my first time here so I hope I post this question at
first post here on stack overflow, hoping to get some advice on how to
First off, there's a bit of background to this issue available on my blog:
First off i'm new here so if I made any mistakes please point them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.