Results 1 to 5 of 5

Thread: Print form question

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Print form question

    I got the code below from hack. Thank you hack. I have a question.. I want to print the form1. I don't want any command button on form1.

    How I can print the form1 If I put the command button on form 2 ?

    Code:
    Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, _
     ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
    
    Private Declare Sub ReleaseCapture Lib "user32" ()
    Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, _
    ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
    
    Private Const VK_MENU As Byte = &H12
    Private Const VK_SNAPSHOT As Byte = &H2C
    Private Const KEYEVENTF_KEYUP = &H2
    
    Private Sub Command1_Click()
    
    
    
    Dim lWidth As Long, lHeight As Long
        Clipboard.Clear
        Call keybd_event(VK_MENU, 0, 0, 0)
        Call keybd_event(VK_SNAPSHOT, 0, 0, 0)
        DoEvents
        Call keybd_event(VK_SNAPSHOT, 0, KEYEVENTF_KEYUP, 0)
        Call keybd_event(VK_MENU, 0, KEYEVENTF_KEYUP, 0)
        
        Printer.Print
        If Width > Printer.ScaleWidth Then
            lWidth = Printer.ScaleWidth
            lHeight = (Printer.ScaleWidth / Width) * Height
        Else
            lWidth = Width
            lHeight = Height
        End If
        
        Printer.PaintPicture Clipboard.GetData, 0, 0, lWidth, lHeight
        Printer.EndDoc
    
    End Sub

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Print form question

    I use code above to print the form1. In form1 , I have command button1. After clicking the command button, It print the form1 but include the commnd button. How I can invisible that command button so that I can print the form1 ?

  3. #3
    PowerPoster Code Doc's Avatar
    Join Date
    Mar 2007
    Location
    Omaha, Nebraska
    Posts
    2,354

    Re: Print form question

    Quote Originally Posted by matrik02
    I use code above to print the form1. In form1 , I have command button1. After clicking the command button, It print the form1 but include the commnd button. How I can invisible that command button so that I can print the form1 ?
    Did you try making the command button invisible (Command1.Visible = False) right after the _Click() and then make it visible (Command1.Visible = True) right before End Sub?
    Doctor Ed

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Print form question

    Quote Originally Posted by Code Doc
    Did you try making the command button invisible (Command1.Visible = False) right after the _Click() and then make it visible (Command1.Visible = True) right before End Sub?
    This is about the only way you could do it as the code is form dependent.

  5. #5

    Thread Starter
    Frenzied Member
    Join Date
    Feb 2007
    Location
    Malaysia
    Posts
    1,370

    Re: Print form question

    It still capture the command button. How to invisible that button after click command button. I want to print the form but it also printing the button.

    Code:
    Private Sub Command2_Click()
           ' Capture the client area of the form.
             Command2.Visible = False
             Form40.Height = Form10.Height
             Form40.Width = Form10.Width
             Set Form40.Picture1.Picture = Nothing
             Set Form40.Picture1.Picture = CaptureClient(Me)
           
             Form40.Picture1.Height = Form10.Height
             Form40.Picture1.Width = Form10.Width
              ' Print the current contents of the picture box.
             MsgBox "Peta akan dicetak", vbInformation, "Cetak..."
             PrintPictureToFitPage Printer, Form40.Picture1.Picture
             Printer.EndDoc
             Command2.Visible = True
             Form40.Show
    
    
    End Sub
    Code:
          '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
          '
          ' CaptureClient
          '    - Captures the client area of a form.
          '
          ' frmSrc
          '    - The Form object to capture.
          '
          ' Returns
          '    - Returns a Picture object containing a bitmap of the form's
          '      client area.
          '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
          '
          Public Function CaptureClient(frmSrc As Form) As Picture
             ' Call CaptureWindow to capture the client area of the form given
             ' its window handle and return the resulting Picture object.
             Set CaptureClient = CaptureWindow(frmSrc.hwnd, True, 0, 0, _
                frmSrc.ScaleX(frmSrc.ScaleWidth, frmSrc.ScaleMode, vbPixels), _
                frmSrc.ScaleY(frmSrc.ScaleHeight, frmSrc.ScaleMode, vbPixels))
          End Function

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