Solved

resize picturebox picture

Posted on 2000-04-22
7
336 Views
Last Modified: 2011-10-03
i am using vb5, and i made a quick browsing and text editing tool.  i expanded it to graphics, but the go off the form.  how do resize the graphic, to stay proportionate, but to fit in the space allocated for them?
0
Comment
Question by:blackc
  • 4
  • 2
7 Comments
 
LVL 1

Expert Comment

by:plasmatek
ID: 2739807
Use an imagebox instead of a picturebox and set image1.stretch to true.

Accept comment as answer if this helps.
0
 

Author Comment

by:blackc
ID: 2739952
thanx anyway, but i already did that, and it distorts the pictures so bad it isn't even funny.  i need to just be able to adjust one length (the longer one) and then that lenght will be entirely inside the available area, and so the shorter side must be 2.  i need to keep it proportional.
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 50 total points
ID: 2740284
This example stretches an image into a picturebox, retaining the aspect ratio of the original picture:

Option Explicit

Private Sub Command1_Click()
    On Error Resume Next
    Dim dx As Long, dy As Long
    Dim sngAspectPic As Single
    Dim pic As StdPicture
    Set pic = LoadPicture("c:\test2.bmp")
    If Not (pic Is Nothing) Then
        Picture1.AutoRedraw = True
        'get image dimensions
        dx = ScaleX(pic.Width, vbHimetric, Picture1.ScaleMode)
        dy = ScaleY(pic.Height, vbHimetric, Picture1.ScaleMode)
        'Get aspect ratio of picture (h/w)
        sngAspectPic = pic.Height / pic.Width
        'Determine if width or height should fill the PictureBox
        If (sngAspectPic > (Picture1.Height / Picture1.Width)) Then
            Picture1.PaintPicture pic, 0, 0, Picture1.Height / sngAspectPic, Picture1.Height
        Else
            Picture1.PaintPicture pic, 0, 0, Picture1.Width, Picture1.Width * sngAspectPic
        End If
    End If
    'Set the picture = to the new image
    Picture1.Picture = Picture1.Image
    Picture1.AutoRedraw = False
    'Clear the old picture
    Set pic = LoadPicture("")
End Sub
0
Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 32

Expert Comment

by:Erick37
ID: 2740294
Some modifications; change

Picture1.Height to
Picture1.Scaleheight

and

Picture1.Width to
Picture1.Scalewidth

in the above code, all occurances.
0
 

Author Comment

by:blackc
ID: 2741630
erick37, i don't know if it works or not because w/ the option explicit in the general declerations, it now has a problem w/ nearly every other variable in my program.  since i am dealing with file paths a lot, there are quite a few variables.  how would i adjust your code or mine so taht they would work together?  i can send you my program, but if you changed anything, i would appreciate a commented explanation of why you canged each thing.  in a test project i did, your code worked beautifully.  now we just need to merge the code.
0
 

Author Comment

by:blackc
ID: 2741686
sorry bout that, i just took a closer look at your code, and realized(feeling pretty stupid afterwards) that all i had to do was to remove teh option explicit and replace (C:\test2.bmp)  with the variable for the file user has selected.  so now it works great!  thanx a lot!
0
 

Author Comment

by:blackc
ID: 2741692
he realy knows his stuff.
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question