Results 1 to 4 of 4

Thread: Coding Issues

  1. #1

    Thread Starter
    Member andrew5578's Avatar
    Join Date
    Dec 2003
    Posts
    51

    Coding Issues

    I am new at Visual Basic. Im in high school and decided to take on programming as an elective. Its turned into my hobby. I need help though. I have a picture box. I want it so that if the user clicks on the picture box, the picture changes. What is the code for that? I tried this
    Code:
    Private Sub PictureBox_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Box1.Click
          Me.PictureBox.Image = location of saved image on harddrive
    End Sub
    aka Ender

  2. #2
    Hyperactive Member ZeroCool's Avatar
    Join Date
    Feb 2002
    Location
    In front of my computer
    Posts
    423
    from memory:

    VB Code:
    1. Me.PictureBox.Image = Image.FromFile("Path")
    Visual Baisc 6 (SP5)
    Windows Xp

  3. #3

    Thread Starter
    Member andrew5578's Avatar
    Join Date
    Dec 2003
    Posts
    51
    Thanks, that helps. Im such a newbie
    aka Ender

  4. #4
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by andrew5578
    Thanks, that helps. Im such a newbie
    one issue though, although you and most people probably dont care about it: if you load the image that way, the image file will be locked until your program unloads, or until you dispose the image. The only simple way that I know to get around this is the get a copy of the loaded image and dispose the one that you loaded from file so the file would get unlocked:

    VB Code:
    1. Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
    2.         Dim imgSrc As Image = Image.FromFile("C:\txtr.bmp")
    3.         PictureBox1.Image = New Bitmap(imgSrc)
    4.         imgSrc.Dispose()
    5.     End Sub
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

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