|
-
Nov 16th, 2009, 04:12 PM
#1
Thread Starter
Member
[RESOLVED] If backgroundimage = then?
Hi All,
Im currently trying to get button depending on what the background is to do something
EG:
Code:
if Button19.BackgroundImage = my.resources.play then
AxWindowsMediaPlayer1.Ctlcontrols.play()
This doesnt work, but is there any other method of doing this?
Thanks In Advance,
Jamie.
-
Nov 16th, 2009, 04:16 PM
#2
Re: If backgroundimage = then?
I am guessing the reason it doesn't work is because setting the BackgroundImage property actually creates a copy of the image you supply, instead of directly setting it to the same image. In that case, checking for equality doesn't work as they are no longer to same object (they are two different images that happen to look the same).
What you can (and really should) do, is use some private (global) variable that 'remembers' the status of your background.
You are the one setting the BackgroundImage (somewhere you haven't shown us), so wherever you do that, you could set some boolean variable to True. Whenever you set the BackgroundImage back to something else, you set the same variable to False.
Now, the boolean variable corresponds to which image is shown in your background, and you can use it to do the conditional check.
-
Nov 16th, 2009, 04:18 PM
#3
Thread Starter
Member
Re: If backgroundimage = then?
ok thats very complex, the images are in resoures area;
Care to provide some code? 
i rarely do booleans
-
Nov 16th, 2009, 04:26 PM
#4
Re: If backgroundimage = then?
I think you need to show some of your code first. Mainly the parts where you are changing the BackgroundImage. You must be changing it in code somewhere, because if you only changed it during design-time, it would never change, and there would be no need for the If statement at all.
-
Nov 16th, 2009, 04:29 PM
#5
Thread Starter
Member
Re: If backgroundimage = then?
well this is the only code that remotely involves it:
Code:
If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsMediaEnded Then
Button19.BackgroundImage = My.Resources.Play
End If
If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsPlaying Then
Button19.BackgroundImage = My.Resources.pause
End If
If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsStopped Then
Button19.BackgroundImage = My.Resources.Play
End If
If AxWindowsMediaPlayer1.playState = WMPLib.WMPPlayState.wmppsPaused Then
Button19.BackgroundImage = My.Resources.Play
End If
-
Nov 16th, 2009, 04:38 PM
#6
Thread Starter
Member
Re: If backgroundimage = then?
ok, i get what u mean now (the images are now all retrieved from the resoures,
but please i havent got a clue how to do booleons or anything without help
-
Nov 16th, 2009, 05:03 PM
#7
Re: If backgroundimage = then?
boolean is just fancy computer talk for true or false. You are already doing boolean logic in those If statements to determine the playstate.
That being said, looking at the image of a button to determine what that button should do is NOT a good idea. The problem is that it creates a dependancy for you to remember that IF you happen to change the button graphic or something to do with it, you may introduce weird bugs that are hard to track down.
Lets say you had a button that is a play/pause button. So when you click it and it shows play it changes to a pause image so that when you click it the playback will be paused.
When you click this button, you can simply look at the playstate of the media player to determine what to do. If its in a state of wmppsPlaying, then you would initiate a pause, otherwise you would initiate a play. Does that make sense?
-
Nov 16th, 2009, 05:06 PM
#8
Thread Starter
Member
-
Nov 16th, 2009, 06:48 PM
#9
Re: [RESOLVED] If backgroundimage = then?
Trust me, not using the text or image of a control to determine logic flow in your app will really make it much easier in the long run. When someone is new to programming, the UI tends to be their first priority, so they build that and then try to build all the code behind it, trying to use the already built UI to shoe horn in the code logic. It should really be the other way around though.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|