5 Replies - 1162 Views - Last Post: 03 October 2012 - 06:50 PM Rate Topic: -----

#1 mattcash83  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 23-June 12

Best way to momentarily change image in picturebox

Posted 03 October 2012 - 06:01 PM

I am writing an MP3 player.

I need to know the best way to change the image in my picture boxes (play button, stop button, next, ...etc) for 1/4 a second when they are clicked. I was thinking I should use a timer, but I cannot wrap my mind around how to efficiently do this. I know I should normally provide some code, but I do not know what part of my code is actually relevant; I am just trying to figure out some logic. Any point in the right direction is appreciated!

Thank!!

Is This A Good Question/Topic? 0
  • +

Replies To: Best way to momentarily change image in picturebox

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2255
  • View blog
  • Posts: 9,444
  • Joined: 29-May 08

Re: Best way to momentarily change image in picturebox

Posted 03 October 2012 - 06:09 PM

What version of the .net framework are planning to target?
Was This Post Helpful? 0
  • +
  • -

#3 mattcash83  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 23-June 12

Re: Best way to momentarily change image in picturebox

Posted 03 October 2012 - 06:16 PM

At the risk of sounding stupid, I would assume 4.0? I am sorry, pretty new at this.
Was This Post Helpful? 0
  • +
  • -

#4 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Best way to momentarily change image in picturebox

Posted 03 October 2012 - 06:41 PM

one method would be to set a timer to 250 milliseconds (approx 1/4 second)
In the timer, set all the buttons to their standard image (this would be the reset after the interval)

When the button is clicked, change to the clicked image and start the timer, after 1/4 seconds, the timer should trigger and reset the images. Make sure you stop the timer at the end of the routine so that it doesn't repeat until the next button click.
Was This Post Helpful? 1
  • +
  • -

#5 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2255
  • View blog
  • Posts: 9,444
  • Joined: 29-May 08

Re: Best way to momentarily change image in picturebox

Posted 03 October 2012 - 06:42 PM

Cos if you are using VS2012, you can utilize the Async & Await keywords.
Along with the async targeting pack you can target down to .net4.0 .
  Public Async Sub MomentarilyChangePictureBoxImage(thePictureBox As PictureBox,
                                                    ChangeImageTo As Image, HowLongToChangeForInMS As Integer)
    Dim CurrentImage = thePictureBox.Image
    thePictureBox.Enabled = False
    thePictureBox.Image = ChangeImageTo
    Await Task.Delay(HowLongToChangeForInMS)
    thePictureBox.Image = CurrentImage
    thePictureBox.Enabled = True
  End Sub


Was This Post Helpful? 0
  • +
  • -

#6 mattcash83  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 41
  • Joined: 23-June 12

Re: Best way to momentarily change image in picturebox

Posted 03 October 2012 - 06:50 PM

View PostCharlieMay, on 03 October 2012 - 06:41 PM, said:

one method would be to set a timer to 250 milliseconds (approx 1/4 second)
In the timer, set all the buttons to their standard image (this would be the reset after the interval)

When the button is clicked, change to the clicked image and start the timer, after 1/4 seconds, the timer should trigger and reset the images. Make sure you stop the timer at the end of the routine so that it doesn't repeat until the next button click.


Beautiful! I new I was just missing it by a touch; I was setting my images reversed from what you just said. It all makes sense to me now............Thanks!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1