Visual Basic - Changing the Picture in a PictureBox during an event?

Discussion in 'OT Technology' started by coronet, Nov 4, 2004.

  1. coronet

    coronet Do Andriods Dream of Electric Sheep?

    Joined:
    Aug 25, 2003
    Messages:
    32,590
    Likes Received:
    0
    Location:
    West Hills, Los Angeles, California
    So here's the deal. I'm writing a simple program in VB, in which I have a PictureBox sort of as a 'decorative image'. But what I want to do, is have the picture changed to another picture (of the same size properties) when an event occours (appling data from 2 InputBoxes into a Label). Is there any code for this? :x:

    Thanks in advance! :)
     
  2. beez

    beez New Member

    Joined:
    Jun 3, 2004
    Messages:
    19,143
    Likes Received:
    0
    Location:
    Queens
    Can't you put the code in under whichever button has to be pressed by the user to input the data?
     
  3. coronet

    coronet Do Andriods Dream of Electric Sheep?

    Joined:
    Aug 25, 2003
    Messages:
    32,590
    Likes Received:
    0
    Location:
    West Hills, Los Angeles, California
    Yeah, I guess. But I don't know what the code is to do it is the problem. Help anyone?
     
  4. Keyzs

    Keyzs OT Supporter

    Joined:
    Nov 3, 2003
    Messages:
    814
    Likes Received:
    0
    Location:
    Charlotte, MI
    VB.NET
    PictureBox1.Image = Image.FromFile("c:\YourImage.jpg")
     
  5. coronet

    coronet Do Andriods Dream of Electric Sheep?

    Joined:
    Aug 25, 2003
    Messages:
    32,590
    Likes Received:
    0
    Location:
    West Hills, Los Angeles, California
    That didn't work. I have an apply button... and I want to make the image change when the user clicks apply (which is the name of the button). Here's the code:

    Code:
        Private Sub cmdApply_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdApply.Click
            Me.picLogo.Image = Image.FromFile("Z:\My Pictures\fred.jpg")
        End Sub
    
    Umm... any suggestions? :dunno:

    Thanks in advance :) :hs:
     
  6. Keyzs

    Keyzs OT Supporter

    Joined:
    Nov 3, 2003
    Messages:
    814
    Likes Received:
    0
    Location:
    Charlotte, MI
    Code:
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            PictureBox1.Image = Image.FromFile("c:\Sample.jpg")
        End Sub
    
    Works for me. VS.NET 2003...
     
  7. PBizme

    PBizme I Got Nothing

    Joined:
    Jan 27, 2002
    Messages:
    729
    Likes Received:
    0
    Location:
    Purdue
    Code:
        
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Label1.Text = TextBox1.Text + TextBox2.Text
            PictureBox1.Image = Image.FromFile("c:\test.gif")
        End Sub
    
    Works for me in VS.NET 2003
     
  8. coronet

    coronet Do Andriods Dream of Electric Sheep?

    Joined:
    Aug 25, 2003
    Messages:
    32,590
    Likes Received:
    0
    Location:
    West Hills, Los Angeles, California
    So none of that worked. :(

    However, me and my team partner did do some ghetto-rigging to produce the same result; have to imageboxes of the same size and location, one disabled until a button is pressed. So... the kind of the same thing; same result at least. My buld error was, hoever, something with security... so it could have been my school's computers disorting the code? I dunno. It's all over, but thanks. :)
     

Share This Page