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 1075761
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:19:06+00:00 2026-05-16T21:19:06+00:00

So basically im making a custom button. Desired Behaviour: When a user mouses over,

  • 0

So basically im making a custom button.

Desired Behaviour:

When a user mouses over, then the mouseover picture will fade in.

When a user mouses off the mouseover/pressed picture will fade out.

Exceptions:

If a user mouses in, or off, while a fade animation is playing, then it will need to:

  • Instantly stop the currently playing animation
  • Start fading into the new animation from current position. Example: Lets say a user mouses over, and the mouseover animation has played, if they were to mouse off, and then mouse back on quickly while the mouseoff animation was still playing, it would not start the mouse in fade from the beginning.. but from where the mouseoff animation had stopped.
  • 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-16T21:19:07+00:00Added an answer on May 16, 2026 at 9:19 pm

    I did a similar thing to this before, and implemented it using GDI+.

    The button should do two things in it’s draw method.

    1. Draw the default button without any regards for transparency.
    2. Draw the mouseove image with a given alpha.

    Use a BackgroundWorker to give you a smooth animation. So on mouseover start the BackgroundWorker and make it run untill Alpha reaches 1.0f. When mouse is removed from button, the worker should reduce Alpha untill it reaches 0.0f. Have a variable called fadingin so that the BackgroundWorker will understand what it should do. Your mouse in and out event should just properly set fadingin to true or false, then start the BackgroundWorker (if it’s not already runnung).

    The BackgroundWorkers DoWork method can look something like this:

    void backgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
      long ticks1 = 0;
      long ticks2 = 0;
      double interval = (double)Stopwatch.Frequency / 60;
      while (true) {
        ticks2 = Stopwatch.GetTimestamp();
        if (ticks2 >= ticks1 + interval) {
          ticks1 = Stopwatch.GetTimestamp();
    
          if(_fadeIn){
            _fadeAlpha += 0.1f;
            if(_fadeAlpha > 1f){
              _fadeAlpha = 1f;
              break;
            }
          }else{
            _fadeAlpha -= 0.1f;
            if(_fadeAlpha < 0f){
              _fadeAlpha = 0f;
              break;
            }
          }
          backgroundWorker.ReportProgress(0);
        }
        Thread.Sleep(1);
      }
      backgroundWorker.ReportProgress(0);
    }
    

    The Stopwatch and loop construct here will make the animation aim for a 60fps animation.

    The backgroundWorker ProgressChanged should just change the ColorMatrix to the proper alpha value, and bind the ColorMatrix to the ImageAttributes, and invalidate the control by calling Invalidate. This has to be done so that the GUI repaint is requested from the main thread, and not the BackgroundWorker thread. If you do this directly from DoWork you will get an exception if you try to modify ImageAttributes while a draw operation is taking place.

    Hope this helps you to make a good smooth animation on your button.

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

Sidebar

Related Questions

I am making an app which will allow the user to click a picture
Long story short, I'm making a custom Swing component that's basically a JTable with
I'm making a custom GUI for my application. Basically my application has multiple 'tabs'.
Hello i'm working on an app where i'm basically just making a custom multi
I am currently making an app that will have multiple timers, which are basically
I'm making a custom control. Basically what I'm looking for is a OnPreInit event
I am basically thinking of making a christmas gift got my girlfriend that will
So I'm basically making an app that adds a count to a number and
Okay, so I am basically making a script to pass post data using cURL.
I'm using AFJSONRequestOperation in an iPhone app (targeting iOS 5) - basically making a

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.