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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T20:21:01+00:00 2026-05-17T20:21:01+00:00

Ok So I’m creating a Windows Forms Application for some guy using C# and

  • 0

Ok So I’m creating a “Windows Forms Application” for some guy using C# and I want to make the UI a bit more interesting for him.

The main form looks like a big dial with custom buttons arranged on it. (I’m saying custom buttons since they are actually simple user controls I’ve created that have a PictureBox and a Label that enlarges when the user points it and then shrink when the mouse cursor is moved outside it. There’s also an Image property which sets the PictureBox‘s Image and is used as the icon of the so called custom button.)

I used two timers named tmrEnlarge and tmrShrink which activate on MouseEnter and MouseLeave events respectively. Basically nothing but a couple of simple functions to increase and decrease the size of the PictureBox used in my custom control and making it look like it’s zooming in…

It works just fine but the problem is, when the mouse hovers several controls at the same time, the animation slows dows (which in my opinion is normal, since timers are not the best way for doing something like I did!)
I tried using threads as well but the problem’s still here! 🙁

What I want to know is what’s the best way for doing something like this?

EDIT:

Here’s the code I used for drawing the image directly on the control without using a PictureBox:

(It’s just a quick version and it leaves residues after drawing the image, which is not important for me right now)

public partial class DDAnimatingLabel : UserControl
{
    public Image Image { get; set; }

    public DDAnimatingLabel()
    {
        InitializeComponent();
    }

    private void DDAnimatingLabel_MouseEnter(object sender, EventArgs e)
    {
        tmrEnlarge.Enabled = true;
    }

    protected override void OnPaint(PaintEventArgs e)
    {
        if (Image != null)
        {
            e.Graphics.DrawImage(this.Image, e.ClipRectangle);
        }
        else
            base.OnPaint(e);
    }

    private void tmrEnlarge_Tick(object sender, EventArgs e)
    {
        if (Size.Width >= MaximumSize.Width)
        {
            tmrEnlarge.Enabled = false;
            return;
        }

        Size s = Size;
        s.Height += 4;
        s.Width += 4;
        Size = s;

        Point p = Location;
        p.X -= 2;
        p.Y -= 2;
        Location = p;
    }

    private void tmrShrink_Tick(object sender, EventArgs e)
    {
        if (tmrEnlarge.Enabled)
            return;

        if (Size.Width == MinimumSize.Width)
        {
            tmrShrink.Enabled = false;
            return;
        }

        Size s = Size;
        s.Height -= 4;
        s.Width -= 4;
        Size = s;

        Point p = Location;
        p.X += 2;
        p.Y += 2;
        Location = p;
    }

    private void DDAnimatingLabel_MouseLeave(object sender, EventArgs e)
    {
        tmrShrink.Enabled = 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-17T20:21:02+00:00Added an answer on May 17, 2026 at 8:21 pm

    I originally misunderstood your question. Some time ago I built an animation system for this kind of thing. Here you can find that code:
    http://pastebin.com/k1XmRapH.

    That is an older ‘version’ of my animation system. It’s crude, but relatively small and easy to understand. Below is a demonstration app that uses the animation system.

    The key points of this system are:

    • Utilize a single timer that provides a timed ‘pulse’ to each runnning animation
    • The pulse uses elapsed time to calculate how much change to apply

    The demonstration app uses an AnimationGroup to alter both Size and Location properties. When the mouse enters the button we first cancel any existing animation and then run an animation to grow the button. When the mouse leaves the button we again cancel any existing animation and then run an animation to return it to normal. Specifying AnimationTerminate.Cancel to AnimationManager.Remove cancels a running animation without calling its End method (which would complete the animation). This leaves the button’s properties in the state they were in at the time we cancelled and smoothly returns the button to normal size.

    using System;
    using System.Drawing;
    using System.Windows.Forms;
    
    class Form1 : Form
    {
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    
        const int PulseInterval = 20;
        const int ButtonAnimateTime = 250;
    
        AnimationManager animate;
        Point[] buttonLocationsNormal, buttonLocationsHover;
        Size buttonSizeNormal, buttonSizeHover;
    
        public Form1()
        {
            Text = "Demo";
            ClientSize = new Size(480, 100);
    
            animate = new AnimationManager { PulseInterval = PulseInterval };
    
            buttonLocationsNormal = new Point[4];
            buttonLocationsHover = new Point[4];
            buttonSizeNormal = new Size(100, 80);
            buttonSizeHover = new Size(120, 100);
    
            for (int n = 0, x = 10; n < 4; n++, x += 120)
            {
                Point normalLocation = new Point(x, 10);
                buttonLocationsNormal[n] = normalLocation;
                buttonLocationsHover[n] = new Point(x - 10, 0);
                Button button = new Button { Text = "Text", Location = normalLocation, Size = buttonSizeNormal };
                button.MouseEnter += (s, e) => AnimateButton(s as Button, true);
                button.MouseLeave += (s, e) => AnimateButton(s as Button, false);
                Controls.Add(button);
            }
        }
    
        private void AnimateButton(Button button, bool hovering)
        {
            int index = Controls.IndexOf(button);
            AnimationGroup group = button.Tag as AnimationGroup;
            if (group != null)
                animate.Remove(group, AnimationTerminate.Cancel);
    
            Point newLocation;
            Size newSize;
            if (hovering)
            {
                newLocation = buttonLocationsHover[index];
                newSize = buttonSizeHover;
            }
            else
            {
                newLocation = buttonLocationsNormal[index];
                newSize = buttonSizeNormal;
            }
            group = new AnimationGroup(
                new PropertyAnimation("Location", button, newLocation, TimeSpan.FromMilliseconds(ButtonAnimateTime), new PointAnimator())
                , new PropertyAnimation("Size", button, newSize, TimeSpan.FromMilliseconds(ButtonAnimateTime), new SizeAnimator())
            );
            button.Tag = group;
            animate.Add(group);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

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.