Solved

Stretching Picture Box

Posted on 1998-12-07
9
300 Views
Last Modified: 2010-05-03
I need to know how to stretch a picturebox...i insist on using picture box and not image box because i need to use the hDC property for my picture box... how do i set the picturebox so that when i enlarge or shrink it, the image will follow suit as well?
0
Comment
Question by:lph
  • 5
  • 4
9 Comments
 
LVL 2

Accepted Solution

by:
JiaH earned 100 total points
ID: 1448691
Use the PaintPicture method of the picture box control.
0
 

Author Comment

by:lph
ID: 1448692
can you give me an example on how to use the PaintPicture method?
0
 
LVL 2

Expert Comment

by:JiaH
ID: 1448693
This an example: (picture1 has the source picture, the following code make it 2* in the picture2. The code can get the picture's actual size if the autosize not been set to true)

    Dim fWidth As Double, fHeight As Double
   
    With Picture1
        If .AutoSize Then
            fWidth = .ScaleWidth
            fHeight = .ScaleHeight
        Else
            fWidth = .ScaleX(.Picture.Height, vbHimetric, .ScaleMode)
            fHeight = .ScaleY(.Picture.Width, vbHimetric, .ScaleMode)
        End If
    End With
    Picture2.PaintPicture Picture1, 0, 0, 2 * fWidth, 2 * fHeight, 0, 0, fWidth, fHeight, vbSrcCopy

When you want shrink it, you just need change the parameters 2*fWidth and 2*fHeight to the Width and Height you needed (should use the same scalemode as that of picture1, use scalex and scaley  to change it when needed.)
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:lph
ID: 1448694
can i know how to flip a bitmap as well using the PaintPicture method... i tried passing negative values as the parameters for the picWidth and picSource, but it wont flip...

can u pls give me an example on this?
thanx in advance!
0
 
LVL 2

Expert Comment

by:JiaH
ID: 1448695
What's the meaning of flip? If you only want to get part of the source file, just modify the code like this:
Picture2.PaintPicture Picture1, destX, destY, destWidth, destHeight, srcX, srcY, srcWidth, srcHeight, vbSrcCopy

Change the dest??? can change the result postion in the destination and the srcX and srcY is the left and top position of the source where the selection start. You can get the help of the method for more detail.

0
 

Author Comment

by:lph
ID: 1448696
what i mean for flip is the left side of the picture box is the mirror image for the right side and the right side is the mirror image of the left side... as in the MS Paint function where you can flip the image... according to the help, i can flip the image when negative values are passed as the destWidth and destHeight...

however i don't get the desired results.... pls help!
0
 
LVL 2

Expert Comment

by:JiaH
ID: 1448697
Then you need call the method two times , first mirror the left part then the right part, what you need is change the dest???.
0
 
LVL 2

Expert Comment

by:JiaH
ID: 1448698
The following code can change the left half part and the right half part ( the autosize of picture1 is true)

With Picture1
        Picture2.PaintPicture Picture1.Picture, 0, 0, .ScaleWidth / 2, .ScaleHeight, .ScaleWidth / 2, 0, .ScaleWidth / 2, .ScaleHeight, vbSrcCopy
        Picture2.PaintPicture Picture1.Picture, .ScaleWidth / 2, 0, .ScaleWidth / 2, .ScaleHeight, 0, 0, .ScaleWidth / 2, .ScaleHeight, vbSrcCopy
    End With
0
 

Author Comment

by:lph
ID: 1448699
the flip method you proposed actually copies the right side to the left side and the left side to the right side..not really what i wanted.. i'm actually trying to create a mirror image of the left side and the right side...
after experimenting for a while, i managed to make the bitmap flip by passing the negative value as the dest width. This is what i wanted:

PicX PaintPicture PicX, picX.Width, 0, -picX.Width, picX.Height,,,,vbSrcCopy

anyway thanks for suggesting the PaintPicture method to me...
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
DIR issue 7 54
Access 2013 combo box not working 3 45
Error when passing an argument to a vb6 that contains  '/' 7 38
Help me. 3 56
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

823 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