简体   繁体   中英

Picturebox change picture after holding down mouse button and rechange after releasing mouse C#

I want to make my PictureBox change the "Button normally" picture to "Button pressed". After I held down the mouse button, PictureBox should change its image from "Button normally" to "Button pressed" and after releasing the mouse key, it should get back to "Button normally". I've uploaded my pictures down below 👇. Thanks in advance ☺

my first image: Button normally

My second image: Button pressed

Edit: My code:

'''C# 
private void pictureBox2_Up(object sender, MouseEventArgs e)
    {
        pictureBox2.Image = Properties.Resources.test_voice_button_pressed;
        say("Hi, im Dude, your smart assistant");
//pictureBox2_Up means MouseUp and the same thing for pictureBox2_Down
    }

private void pictureBox2_Down(object sender, MouseEventArgs e)
{
    pictureBox2.Image = Properties.Resources.test_voice_button_normal;
}
'''

You should use MouseDown and MouseUp actions. Here's the code:

       private void pictureBox2_Up(object sender, MouseEventArgs e)
    {
        pictureBox2.Image = Properties.Resources.test_voice_button_normal;
        say("Hi, im Dude, your smart assistant");
    }

    private void pictureBox2_Down(object sender, MouseEventArgs e)
    {
        pictureBox2.Image = Properties.Resources.test_voice_button_pressed;
    }

Special thanks to @user700390 and @CaiusJard.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM