Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Resize an Image Control using VB

Status
Not open for further replies.

shannonp

IS-IT--Management
Nov 13, 2001
289
NZ
I have a report where for each record I have a textbox called link1 containing a path and filename (ie "c:\pic1.bmp"). I then linked link1.value to an Image Control...this part works fine.

NOW...

Not all records have links to pictures and I don't want wasted space in the report so my idea was to set initial height and width values of the Image Control to zero. Then, only when link1 was Not Null I would set height and width of the image control to my desired size. I find that in VB I do not have control over the image control's height and width attributes...why is this? Has anyone out there got ideas or solutions to my dilemma?
 
Won't the "Can Shrink" and "Can Grow" properties for the details section of the report work? These allow a section to grow or shrink vertically based on how much data is in them. I imagine it will work for an image as well, but do not know for sure. Jim Lunde
compugeeks@hotmail.com
We all agree your theory is crazy, but is it crazy enough?
 
Thanks for the insight Jim. All very fine and dandy to assume though. But, if I done that then it would resize the image to its original dimensions which I do not want. Unless I go through hundreds of pictures and resize them to the same dimension (where I need a small dimension and a large dimension), it would produce an undesirable result. Again thanks for your input.
 
I'm not a VBA guru, but I've got a potential solution. Assuming VBA has the ability to return a boolean value where or not "Link1.Value" actually exists, then try just setting the Image Control's Visable property accordingly.

If FileExists Link1.Value Then
Pic1.Visible = TRUE
Else
Pic1.Visible = FALSE
End If

Then setting the detail section of the reports can shrink/grow property to True should work. Obviously FileExists is not the right syntax, but you get the idea.
Hope that helps - NT
 
I have exactly the same problem as Shannonp1. I don't want to waste space in my report if a the record don't have a picture.

It has been suggested here that you could use "can grow/can shrink", I don't think this would work as the Image control don't have this property.

Another suggestion was to set visible to false, I don't think this would work either as the visible property only makes the image invisible but will not change the size.


Have I missed something? Did you Shannon1 find any solution? or have anybode else a solution to this problem?


Thanks in advance
Hakan Haskel
 
Sorry HHaskel

I haven't been able to solve this one yet
 
I have found a solution, it is possible to change the imagesize in the Detail_Format event, like this:
Code:
Private Sub Detail_Format(Cancel As Integer, FormatCount As Integer)
    Me.imgPicture.Picture = Nz(Me.txtImagePath)
    Me.imgPicture.Height = Me.txtImageSize
End Sub

Now with "Can Grow" set on the detailsection, I can make the image as large or small as I want.


/Hakan Haskel
 
Thanks Hakan

I try this and let you know how it gets on :)

Thanks for the help
[yinyang]
 
Anyone have any suggestions for resizing and image using Zoom or Stretch where the quality of the image is still intact without distortion?

DH
 
DH-- Zoom won't distort, stretch will. the ideal solution, of course, is to have your images all the right size to begin with. incidentally, if you want an easy way to convert hundreds of files to all the same size, play around with batch files under File/Automate/Batch in Photoshop. that feature is sweeeeeet.
 
THOSE USING HHASKIL'S SOLUTION:

i fought for hours with it until i finally figured out that VB won't understand inches. make sure the text box you call to declare height is in twips, not inches.

From MS Help:
You can use the ImageHeight property in Visual Basic to determine the height in twips (twip: Unit of measurement that is equal to 1/20 of a point, or 1/1440 of an inch. There are 567 twips in a centimeter.) of the picture in an image control. Read/write Long.

steam was coming out of my ears until i realized this!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top