Results 1 to 9 of 9

Thread: [RESOLVED] If backgroundimage = then?

  1. #1

    Thread Starter
    Member
    Join Date
    Aug 2009
    Location
    England
    Posts
    38

    Resolved [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.

  2. #2
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    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.

  3. #3

    Thread Starter
    Member
    Join Date
    Aug 2009
    Location
    England
    Posts
    38

    Re: If backgroundimage = then?

    ok thats very complex, the images are in resoures area;

    Care to provide some code?

    i rarely do booleans

  4. #4
    PowerPoster
    Join Date
    Apr 2007
    Location
    The Netherlands
    Posts
    5,070

    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.

  5. #5

    Thread Starter
    Member
    Join Date
    Aug 2009
    Location
    England
    Posts
    38

    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

  6. #6

    Thread Starter
    Member
    Join Date
    Aug 2009
    Location
    England
    Posts
    38

    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

  7. #7
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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?

  8. #8

    Thread Starter
    Member
    Join Date
    Aug 2009
    Location
    England
    Posts
    38

    Resolved Re: If backgroundimage = then?

    Thats exactly what im doing, ill guess ill just do how you said

    Thanks Thou, just tried to make it simplier :P



    THANKKKKKKKKKKKKKKS!

  9. #9
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    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
  •  



Click Here to Expand Forum to Full Width