Results 1 to 3 of 3

Thread: Changing a picture box image.

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2008
    Posts
    24

    Changing a picture box image.

    Hi again, I am stuck.... I have a picture box on my form that has a reference to a image online. What I want to do is on the press of a button allow the user to swap the image to another of there choice whilch they find on line.

    So for example: Image.jpg is loaded by default and on the enter button Image2.gif replaces it.

    Any help, greatly appreciated.

    Thanks again,
    A4.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,427

    Re: Changing a picture box image.

    There are two ways. If you want to center or otherwise place the picture in the picturebox then use MyPictureBox.PaintPicture Image2.gif (followed by some parameters that you should look up). The other way is Set Picture1.Picture = LoadPicture("Image2.gif").

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Changing a picture box image.

    1. Allow your picturebox to accept Ctrl+V. This can be done by trapping the picturebox KeyDown event. Here are some values you want to capture
    KeyCode = vbKeyV, Shift = vbCtrlMask

    2. Assuming the user copied the web image into memory, here is what you will want to do to add it to your picturebox
    Code:
    If Clipboard.GetFormat(vbCfBitmap)=False Then
       ' provide some message, image is not a bitmap -- could be WMF, EMF, PNG, etc
       ' JPGs are fine even though they are not bitmaps
    Else 
       Set Picture1 = Clipboard.GetData()
       SavePicture Picture1, [path/filename]
    End If
    Now that you have the picture and saved it somewhere, your application will need to know that it has been done and where it was saved, so that when app opens again in near future, it can go and retrieve it. This is where INI files or registry settings can be useful.

    P.S. GIFs can be loaded too, however, not the transparent type. When they are converted to bitmaps .GetData, transparency is lost. Getting transparent GIFs from clipboard into VB takes more work.

    Edited: Just saw you posted a related topic. If the case is that you downloaded an image from some web source, do as MartinLiss recommended: Use LoadPicture along with the full path & file name.
    Last edited by LaVolpe; Oct 26th, 2008 at 10:33 PM.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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