Results 1 to 6 of 6

Thread: Picturebox (loadpicture with an offset)

Threaded View

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

    Re: Picturebox (loadpicture with an offset)

    See my previous reply also. In that reply I offered a way to scale the image to your picturebox, but you wanted to offset it, so with slight modifications of the previous post, we have the following
    Code:
    Private Sub LoadAndOffset(FileName As String, Destination As VB.PictureBox, xOffset As Long, yOffset As Long)
        Dim tPic As StdPicture
        Dim srcCX As Long, srcCY As Long
        
        On Error Resume Next
        Set tPic = LoadPicture(FileName)
        If Err Then 
            Err.Clear
            Exit Sub
        End If
        On Error Goto 0
        
        With Destination  ' the .Cls & .AutoRedraw can be done outside of this routine if desired; does not have to be done here
            .Cls
            .AutoRedraw = True
        End With
        
        With tPic
            srcCX = Destination.ScaleX(.Width, vbHimetric, vbPixels)
            srcCY = Destination.ScaleY(.Height, vbHimetric, vbPixels)
    
            ' Draw to scale. Don't remove the +0& below else errors
            .Render Destination.hDC, xOffset + 0&, yOffset + 0&, srcCX + 0&, srcCY + 0&, _
                0&, .Height, .Width, -.Height, ByVal 0&
        End With
        Destination.Refresh 'this can be called outside of this routine; does not need to be done here
    
    End Sub
    Edited: The +/- offsets must be passed as pixels.
    Last edited by LaVolpe; Feb 20th, 2009 at 11:54 AM.
    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