CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2001
    Posts
    65

    It works once and doesn`t work the next time!!!...

    Hi all,

    I have two images : Image1 and Image2.

    I have two buttons : Button1 and Button2.

    The code for button1 is this :
    Image1.Picture = Image2.Picture.
    This changes the images on the click of the button.

    The code for button2 is :
    Image2.Picture = Image1.Picture.
    This does vice versa.

    The problem is, if I think click the first button AGAIN to switch back, nothing happens, the same for button2. How can I fix this?

    Mark


  2. #2
    Join Date
    Feb 2000
    Location
    Indiana USA
    Posts
    193

    Re: It works once and doesn`t work the next time!!!...

    It doesn't work because once you change Image1.picture to Image2.picture, then Image1.picture is the same as Image2.picture, so button2 is working, but you see nothing because Image1.picture is now the same as Image2.picture.
    There is no longer a different picture for Image2.picture to change to


  3. #3
    Join Date
    Jun 2001
    Posts
    65

    Re: It works once and doesn`t work the next time!!!...

    Is there any way I can resolve this then?

    Mark




  4. #4
    Join Date
    Jan 2000
    Location
    Indonesia
    Posts
    6

    Re: It works once and doesn`t work the next time!!!...

    Store the old picture1 to a temporary place, e.g. a hidden picture box, or a variable of type Picture.

    -----------------
    Visit: http://www.ezoutliner.com

  5. #5
    Join Date
    Jun 2001
    Posts
    65

    Re: It works once and doesn`t work the next time!!!...

    I made a copy and stored in it a picture box with visible set to False. I checked the original code and ran again, but it still didn`t work - it only changed once.

    Mark


  6. #6
    Join Date
    Jan 2000
    Location
    Indonesia
    Posts
    6

    Re: It works once and doesn`t work the next time!!!...

    If you want, I can check out your code. Just tell me what process do you intended to do, and I'll see what I can do. Send your code (or a sample form) and your comments to my email: [email protected]



    -----------------
    Visit: http://www.ezoutliner.com

  7. #7
    Join Date
    Jul 2000
    Location
    Milano, Italy
    Posts
    7,726

    Re: It works once and doesn`t work the next time!!!...

    Here is an example. You may have to comment two lines to adjust this to your purpouse.

    To copy this code: copy and paste to WordPad (not Notepad!).
    Then select from WordPad, copy, and paste in VB (Shree suggestion).


    option Explicit
    Dim oldImg1 as Object
    Dim oldImg2 as Object
    private Sub Command1_Click()
    If Image1.Picture <> Image2.Picture then
    Image1.Picture = Image2.Picture
    else
    Image1.Picture = oldImg1
    'do you want the original image2 to be restored too?
    'or comment the following line
    Image2.Picture = oldImg2
    End If
    End Sub
    private Sub Command2_Click()
    If Image1.Picture <> Image2.Picture then
    Image2.Picture = Image1.Picture
    else
    Image2.Picture = oldImg2
    'do you want the original image1 to be restored too?
    'or comment the following line
    Image1.Picture = oldImg1
    End If
    End Sub

    private Sub Form_Load()
    set oldImg1 = Image1.Picture
    set oldImg2 = Image2.Picture
    End Sub



    'have fun.

    Special thanks to Lothar "the Great" Haensler, Tom Archer, Chris Eastwood, Bruno Paris and all the other wonderful people who made and make Codeguru a great place. Come back soon, you Gurus.
    ...at present time, using mainly Net 4.0, Vs 2010



    Special thanks to Lothar "the Great" Haensler, Chris Eastwood , dr_Michael, ClearCode, Iouri and
    all the other wonderful people who made and make Codeguru a great place.
    Come back soon, you Gurus.

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

Featured