CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2001
    Posts
    1

    printout problem

    while taking printouts with printform method on a laser printer. the ms-flexgrid with the contents are displayed completely black.


  2. #2
    Join Date
    Jun 2006
    Location
    Venezuela
    Posts
    37

    Re: printout problem

    I have the same problem... I'm still looking for an answer. Please let me know if you find the way to solve it

    ... Well, if you still there
    THANKS FOR READING: elvagonumero1
    "el hijo perd?*o de Venezuela"--> Everyone is UnDefeatable In Dreams, So... Make'em Real
    ...have a good day

  3. #3
    Join Date
    Jun 2004
    Location
    Kashmir, India
    Posts
    6,808

    Re: printout problem

    Quote Originally Posted by elvagonumero1
    I have the same problem... I'm still looking for an answer. Please let me know if you find the way to solve it

    ... Well, if you still there
    Please don't post the same question in multiple threads. This way you are not helping yourself.

  4. #4
    Join Date
    Apr 2002
    Location
    Melbourne, Victoria, Australia
    Posts
    1,792

    Re: printout problem

    I'm in the process of doing this myself - this is working, but not for maximised forms (ie this is still a work in progress - see the original links for further clarification)

    Code:
    ' Print an image of the form
    ' Code Source:
    '   http://vb-helper.com/howto_print_picturebox.html
    '   http://www.codeproject.com/system/keyboard.asp
    
    Private Sub PrintPictureBoxImage( _
        ByVal oForm As Form, _
        ByVal picHidden As PictureBox, _
        Optional ByVal fit_to_printer = False)
        
        Dim FormPosition As POINTAPI
    ' NB 11 Oct 2006 - Use oForm.WindowState to figure out if the form is maximised (WindowState = 2)
    ' or is not maximised.
    
    ' If oForm.WindowState = 2 then ' form is maximised
    
    ' else
    ' and put the endif somewhere.
    
    
       ' On Error Resume Next
       On Error GoTo ErrTrap
       Screen.MousePointer = vbHourglass
    
    '    '' Copy the form's image to the clipboard by sending an 'Alt' key press.
        Clipboard.Clear
       keybd_event VK_MENU, 0, 0, 0
        'keybd_event VK_MENU, &H45, VK_SNAPSHOT, 0
        DoEvents
    
        ' Press Print Scrn.
    '    keybd_event VK_SNAPSHOT, 1, 0, 0
        keybd_event VK_SNAPSHOT, 0, 0, 0
        DoEvents
    
        '' Release Alt.
        keybd_event VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0
        DoEvents
        keybd_event VK_MENU, 0, KEYEVENTF_KEYUP, 0
        DoEvents
    
        ' Copy the image into the hidden PictureBox:
        'need to reference the clipboard first
        Dim X As Boolean
            X = Clipboard.GetFormat(vbCFBitmap)
        DoEvents
        On Error Resume Next
        picHidden.Picture = Clipboard.GetData(vbCFBitmap)
        DoEvents
        On Error GoTo 0
        ' Get the form's location on the screen (in pixels)
        FormPosition.X = 0
        FormPosition.Y = 0
        ClientToScreen oForm.hwnd, FormPosition
    
        Dim ScaleModeX As Single, ScaleModeY As Single
        
        ' Convert into the printer's scale mode.
        ScaleModeX = oForm.ScaleX(FormPosition.X, vbPixels, picHidden.ScaleMode)
        ScaleModeY = oForm.ScaleY(FormPosition.Y, vbPixels, picHidden.ScaleMode)
        If Err <> 0 Then
            ' the main form is an MDIForm.  For some reason ScaleX/ScaleY are not supported
            ' in MDIForms. So just print the whole screen
            ScaleModeX = 0
            ScaleModeY = 0
            Err.Clear
        End If
        
        ' We've screen grabbed the entire screen.  Now clip out and print only the active form
        Dim ClipX As Single, ClipY As Single, ClipWidth As Single, ClipHeight As Single
        
        ClipX = ScaleModeX - 40 ' Magic number to include form left side border
        ClipY = ScaleModeY - 330 ' Magic number to include the Title bar into the clipped region
        ClipWidth = oForm.Width 'oForm.ScaleX(oForm.Width, vbPixels, picHidden.ScaleMode)
        ClipHeight = oForm.Height ' oForm.ScaleY(oForm.Height, vbPixels, picHidden.ScaleMode)
        
        Dim LeftMargin As Single, TopMargin As Single, RightMargin As Single
        LeftMargin = 1440 / 3 ' 1440 Twips = 1 inch
        RightMargin = LeftMargin
        TopMargin = 1440 / 3
        
        ' Print image to printer:
        
        Printer.Orientation = vbPRORLandscape ' 2
        
        Printer.Font.Size = 10
        Printer.CurrentY = TopMargin
        Printer.CurrentX = LeftMargin
    '    Printer.Print "Date: " & Now
    '    Printer.CurrentX = LeftMargin
    '    'Printer.Print "Form: " & oForm.Caption & " (" & oForm.Name & ")"
    '    Printer.CurrentX = LeftMargin
    '    'Printer.Print "App Version: " & gsAppVersion
    '    Printer.CurrentX = LeftMargin
    '    'Printer.Print "Server: " & gsServer
    '    Printer.CurrentX = LeftMargin
    '    'Printer.Print "Database: " & gsDatabase
    '    Printer.CurrentX = LeftMargin
    '    'Printer.Print "Database Version: " & gsDBVersion
        
        Dim PrintX As Single, PrintY As Single, PrintWidth As Single, PrintHeight As Single
        If (oForm.Width + LeftMargin + RightMargin) > Printer.Width Then
            ' Need to scale down the image to fit within the side margins
            PrintX = LeftMargin
            PrintY = TopMargin + Printer.CurrentY ' Print to top of page, allowing a small margin
            Dim AspectRatio As Single
            PrintWidth = (Printer.Width - LeftMargin - RightMargin) ' Adjust width to printer's page width
            AspectRatio = oForm.Width / PrintWidth
            PrintHeight = oForm.Height / AspectRatio
        Else
            ' No need to scale if the form width is narrower than the area within the side margins
            'PrintX = (Printer.Width - oForm.Width - LeftMargin) / 2 ' centre image horizontally on page
            PrintX = LeftMargin ' align left
            PrintY = (TopMargin / 2) + Printer.CurrentY ' Print after the text, allowing 1/2 a "top margin" amount of space
            PrintWidth = oForm.Width
            PrintHeight = oForm.Height
        End If
        
        Printer.PaintPicture picHidden.Picture, PrintX, PrintY, PrintWidth, PrintHeight, ClipX, ClipY, ClipWidth, ClipHeight
        Printer.EndDoc
        Screen.MousePointer = vbDefault
        If Err <> 0 Then
            MsgBox ("Error while printing (" & Err.Number & "): " & Err.Description)
        End If
        On Error GoTo 0
    Exit Sub
    ErrTrap:
    MsgBox "Error: " & Err.Number & vbCrLf & Err.Description
    On Error GoTo 0
    
    End Sub
    Be nice to Harley riders...

  5. #5
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: printout problem

    I used to have to run this DOS command back in the Laser Printer days. Produced grey-scale automatically from color screen prints.
    Just loading it before my app started was good enough.

    Loads a program that can print graphics.

    GRAPHICS [type] [[drive:][path]filename] [/R] [/B] [/LCD]
    [/PRINTBOX:STD | /PRINTBOX:LCD]

    type Specifies a printer type (see User's Guide and Reference).
    [drive:][path]filename
    Specifies the file containing information on supported printers.
    /R Prints white on black as seen on the screen.
    /B Prints the background in color for COLOR4 and COLOR8 printers.
    /LCD Prints using LCD aspect ratio.
    /PRINTBOX:STD | /PRINTBOX:LCD
    Specifies the print-box size, either STD or LCD.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

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

Featured