Results 1 to 6 of 6

Thread: [RESOLVED] Printing picture box - alignment issue

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    259

    Resolved [RESOLVED] Printing picture box - alignment issue

    im using this code to print a picture box

    Code:
    Picture1.Picture = LoadPicture("C:\scans\5.bmp")
    
    Printer.PaintPicture Picture1.Picture, -500, 800, Picture1.Width * 0.4, Picture1.Height * 0.3

    the image file dimensions are 296 x 420. my problem is i cant get the width and height correct cause i want to shrink the image to about an inch high and 3/4 inch wide. when i use the above it is like the image is not centered. i dont mean the x & y cordinates but the image itself is to the left. hope that makes sense.

  2. #2
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Printing picture box - alignment issue

    -500 moves the picture to the left. Try changing it to see if the results are what you are looking for.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  3. #3
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Printing picture box - alignment issue

    This will print the image one inch high with the width being proportional to the original picture in the center of the page.
    Code:
    Private Sub Command1_Click()
    Dim intWidth As Integer
    Dim intHeight As Integer
    Dim sngRatio As Single
    Dim x As Integer
    Dim y As Integer
    
        Picture1.Picture = LoadPicture("C:\scans\5.bmp")
    
        '   Get the new width and height for the printed image
        '   Here the image will be 1440 twips high - 1 inch
        '   The width will be proportional to the original image
        sngRatio = 1440 / Picture1.ScaleHeight
        intHeight = 1440 '
        intWidth = Picture1.ScaleWidth * sngRatio
        
        
        '   Find the location to print the image in the center of the page
        x = (Printer.ScaleWidth - intWidth) / 2
        y = (Printer.ScaleHeight - intHeight) / 2
        
        Printer.PaintPicture Picture1.Picture, x, y, intWidth, intHeight
        '   Release the job to the printer
        Printer.EndDoc
    
    End Sub

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    259

    Re: Printing picture box - alignment issue

    Ah i was all wrong. your code make the image look just like the original. the only issue i have now as your comments say, the image is in the center. i need it to be at the top left, to the left of the text i have in this code. how can i adjust the physical position x cord and y cord's. here is what i have now

    Code:
    Dim intWidth As Integer
    Dim intHeight As Integer
    Dim sngRatio As Single
    Dim x As Integer
    Dim y As Integer
    
        Picture1.Picture = LoadPicture("C:\scans\5.bmp")
    
        '   Get the new width and height for the printed image
        '   Here the image will be 1440 twips high - 1 inch
        '   The width will be proportional to the original image
        sngRatio = 1900 / Picture1.ScaleHeight
        intHeight = 1900 '
        intWidth = Picture1.ScaleWidth * sngRatio
        
        
        '   Find the location to print the image in the center of the page
        x = (Printer.ScaleWidth - intWidth) / 2
        y = (Printer.ScaleHeight - intHeight) / 2
        
        Printer.PaintPicture Picture1.Picture, x, y, intWidth, intHeight
        
    Printer.FontSize = 11
    
        Printer.CurrentX = 300: Printer.CurrentY = 500: Printer.FontBold = True: Printer.Print "WELLINGTON REGIONAL MEDICAL CENTER"
        Printer.FontSize = 10
        Printer.CurrentX = 2000: Printer.CurrentY = 1000: Printer.Print "Name: " & FirstNameBox.Text & " " & LastNameBox.Text
        
        Printer.CurrentX = 2000: Printer.CurrentY = 1300: Printer.Print "Date:   " & Date
        Printer.CurrentX = 2000: Printer.CurrentY = 1600: Printer.Print "Time:  " & Format(Time, "h:mm AM/PM")
        Printer.CurrentX = 2000: Printer.CurrentY = 1900: Printer.Print "Entrance:  " & strEntrance
         Printer.CurrentX = 2000: Printer.CurrentY = 2200: Printer.Print "Destination: "
         Printer.CurrentX = 2000: Printer.CurrentY = 2500: Printer.FontSize = 15: Printer.Print strDestination
        
        Printer.EndDoc

  5. #5
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141

    Re: Printing picture box - alignment issue

    x = 0 and y = 0 will print the image at the top left of the page.

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Jun 2003
    Posts
    259

    Re: Printing picture box - alignment issue

    thats it. thanks

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