Results 1 to 9 of 9

Thread: How to scale the image to fix with picturebox

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    How to scale the image to fix with picturebox

    I have problem here, How to fix the image to the picture box, My picturebox change it size when loading the image. How to fix this size of image to fix with picturebox scale?


    Private Sub ListView3_ItemClick(ByVal item As MSComctlLib.ListItem)

    Pesttable.MoveFirst
    Pesttable.Move CLng(item.Index - 1)
    sTarikh = item.Text
    Command21.Enabled = True
    Command22.Enabled = True
    Form18.getID = Pesttable.Fields("id").Value
    Text21.Text = Pesttable.Fields("Nama Perosak").Value & ""
    Text23.Text = Pesttable.Fields("Nama Sintifik").Value & ""
    Text24.Text = Pesttable.Fields("Tanda serangan").Value & ""
    Picture2.Cls
    Set Picture2 = Nothing 'clear the image
    Picture2.AutoRedraw = True
    Picture2.ScaleMode = vbPixels
    On Error GoTo error3:

    Picture2.PaintPicture LoadPicture(Pesttable.Fields("Gambar")), 0, 0, 200, 200
    Exit Sub
    error3:
    If Err.Number = 481 Then
    Dim strImagePath As String
    strImagePath = App.Path & "\ancaman padi\NoImage.gif"
    Picture2.Picture = LoadPicture(strImagePath)
    Exit Sub
    End If

    End Sub

  2. #2
    Addicted Member
    Join Date
    Jul 2007
    Posts
    146

    Re: How to scale the image to fix with picturebox

    Quote Originally Posted by matrik02
    I have problem here, How to fix the image to the picture box, My picturebox change it size when loading the image. How to fix this size of image to fix with picturebox scale?
    You have the Autosize property set to true, that way the picturebox adjusts to the size of the picture.
    Jottum™
    XpVistaControls , (transparent) usercontrols for XP, Vista and 7 with W2K legacy support.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: How to scale the image to fix with picturebox

    My image is larger then the picturebox. So the image only display half..How to resize the image and retain the picturebox size? If I do autosize =true, the picturebox changes it size, I want to retain the picturebox size, just change the image size only to fix with picturebox size

  4. #4
    Addicted Member
    Join Date
    Jul 2007
    Posts
    146

    Re: How to scale the image to fix with picturebox

    Quote Originally Posted by matrik02
    My image is larger then the picturebox. So the image only display half..How to resize the image and retain the picturebox size? If I do autosize =true, the picturebox changes it size, I want to retain the picturebox size, just change the image size only to fix with picturebox size
    Unless you need the additional properties a picturebox supplies, why don't you use an Image? It has a Stretch property.
    Jottum™
    XpVistaControls , (transparent) usercontrols for XP, Vista and 7 with W2K legacy support.

  5. #5
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: How to scale the image to fix with picturebox

    To resize the picture for a picturebox control you will need to use the StretchBlt API.
    Attached Files Attached Files

  6. #6
    New Member
    Join Date
    May 2009
    Posts
    4

    Re: How to scale the image to fix with picturebox

    I have source code showing how to scale a image up or down
    http://ess-image.com/Graphic/Image_P...ZoomImage.aspx

  7. #7
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: How to scale the image to fix with picturebox

    ess-image,

    This is the second time I've seen this link to your .NET solution. This forum is for VB6 which means vb PRIOR to .net.

    Now, I'm sure the OP would be happy to look at any VB6 solution you have.

    Thanks
    Option Explicit should not be an Option!

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

    Re: How to scale the image to fix with picturebox

    Hmmm, look at the date of the OP's post and the last post before today: Post #5, over a year old.
    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}

  9. #9
    Frenzied Member
    Join Date
    Mar 2009
    Posts
    1,182

    Re: How to scale the image to fix with picturebox

    Didn't even see that...
    Option Explicit should not be an Option!

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