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

  • SEARCH
  • Home
  • 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 6997671
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:18:46+00:00 2026-05-27T20:18:46+00:00

I have a class that currently switches between 2 images for normal and mouse

  • 0

I have a class that currently switches between 2 images for normal and mouse over states, but I would like to add a subtle animation that switches between the 2.

Is there any (simple) way to have a button animate from one image to the next such as the buttons do in the IE 9 browser?

EDIT:

Here is the final solution that I used for the OnPaint overload thanks to the answer by joe_coolish

protected override void OnPaint(PaintEventArgs e)
    {
        e.Graphics.DrawImage(_normalImage, 0, 0);

        ColorMatrix matrix = new ColorMatrix();
        matrix.Matrix33 = _opacity;

        ImageAttributes attributes = new ImageAttributes();
        attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);

        e.Graphics.DrawImage(_hotImage, this.DisplayRectangle, 0, 0,
            this.DisplayRectangle.Width, this.DisplayRectangle.Height, GraphicsUnit.Pixel, attributes);

        if (_opacity < 1 && _over)
        {
            _opacity += 0.02f;
            _opacity = Math.Min(1, _opacity);
            this.Invalidate();
        }
        if (_opacity > 0 && !_over)
        {
            _opacity -= 0.02f;
            _opacity = Math.Max(0, _opacity);
            this.Invalidate();
        }
    }

I ended up having to prevent the opacity from being set above 1 or below 0 or else I ended up with some strange behaviors.

Note: it is also important to make sure the control is double buffered or else there is bad flickering.

this.SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
  • 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-27T20:18:47+00:00Added an answer on May 27, 2026 at 8:18 pm

    How different are the images? If you want a “Fade in/out” type thing, try something like this:

        private float _opacity = 0.0f;
        private bool _over = false;
    
        protected override void OnPaint(PaintEventArgs e)
        {
            e.Graphics.DrawImage(imgOne);
    
            ColorMatrix matrix = new ColorMatrix();
            matrix.Matrix33 = _opacity; //opacity 0 = completely transparent, 1 = completely opaque
    
            ImageAttributes attributes = new ImageAttributes();
            attributes.SetColorMatrix(matrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap);
    
            e.Graphics.DrawImage(imgTwo, new Rectangle(0, 0, imgTwo.Width, imgTwo.Height), 0, 0, imgTwo.Width, imgTwo.Height, GraphicsUnit.Pixel, attributes);
    
            if(_opacity < 1 && _over)
            {
                _opacity += 0.05f;   //  Play with this!!
                Invalidate();
            }
            if(_opacity > 0 && !_over)
            {
                _opacity -= 0.05f;   //  Play with this!!
                Invalidate();    
            }
        }
    

    And then just set the _over bool when your mouse goes in and out!

    This is a really rough set of code, and IDK if it’ll even compile, but that’s a pretty good starting point!

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

Sidebar

Related Questions

Currently I have a class that looks like this: public class MyClass : IMyClass
I currently have service classes that look something like this public class UserService :
I have a class that currently has several methods that take integer parameters. These
Good evening, In my app that I'm currently developing, I have a class that
Currently I have a class that is extending the ListActivity class. I need to
We currently have a utilities class that handles a lot of string formatting, date
In the data structures class that I am currently taking, we have been tasked
I'm currently working on Mangler's Android implementation. I have a java class that looks
I'm currently writing a class that implements the SeekableIterator interface and have run into
Currently I have created a ABCFactory class that has a single method creating ABC

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.