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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T02:58:12+00:00 2026-06-04T02:58:12+00:00

I am using a custom control that inherits from a picture box to simulate

  • 0

I am using a custom control that inherits from a picture box to simulate a button. I have most of the functionally I want working correctly. I want to put something in that will simulate a button press. So that when the user presses the button something will happen to the image on the control for a split second.
Is the code below an ok solution for this or can someone suggest a better method.

Would it be using a timer that replaces the image after time x or something like that?

Thanks

 private void MediaButton_MouseClick(object sender, MouseEventArgs e)
        {
            this.Image = this.downImage;
            this.Invalidate();
            this.Refresh();

            //Do something
            System.Threading.Thread.Sleep(200);

            this.Image = this.upImage;
            this.Invalidate();
            this.Refresh();
        }

Update:
This is for a touch screen device

  • 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-06-04T02:58:14+00:00Added an answer on June 4, 2026 at 2:58 am

    No, you don’t want to use Thread.Sleep(xx) here… In fact, just about any time you see code using that, you can assume it’s wrong or at least a very bad idea. You also don’t want a timer, because you don’t want to wait a pre-determined amount of time.

    Instead, let the user determine how long the “down” or “active” image is displayed. Sync it up with the MouseDown and MouseUp events. Change the image to your “down” or “active” image when the MouseDown event is raised, and reset it back to the original image in the MouseUp event.

    private void MediaButton_MouseDown(object sender, MouseEventArgs e) 
    {
        MediaButton.Image = downImage;
    }
    
    private void MediaButton_MouseUp(object sender, MouseEventArgs e) 
    {
        MediaButton.Image = upImage;
    }
    

    Your “down” or “active” image will be displayed as long as the user is clicking the button (has their mouse button down over the control), and then removed when they release the mouse button.

    You get the kind of visual feedback you’re looking for, without any of the bad design.

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

Sidebar

Related Questions

Background I have a custom control that inherits from a TreeView and is modified
I'm attempting to create a custom control that inherits from System.Web.UI.WebControls.ListView . Codebehind: using
Problem I have a custom tab control using Chrome-shaped tabs that binds to a
I have a custom control that has an event. I have a window using
I have a custom control which inherits from System.Web.UI.Control and some of its properties
I've create a WinForms control that inherits from System.Windows.Forms.UserControl...I've got some custom events on
I have a question about extending a custom control which inherits from UserControl. public
Aloha, I have a custom control that I need to instantiate from within a
I have a custom control that I'm using as a rubber band which paints
In my project I am using a custom usercontrol that inherits from devexpress gridcontrol.

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.