home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Toolbox / Visual Basic Toolbox (P.I.E.)(1996).ISO / codeprnt / clipprnt / clipprnt.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-07-04  |  4.8 KB  |  128 lines

  1. VERSION 2.00
  2. Begin Form frmClipPrt 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Clipboard Printer"
  5.    ClientHeight    =   0
  6.    ClientLeft      =   2820
  7.    ClientTop       =   4860
  8.    ClientWidth     =   2460
  9.    ClipControls    =   0   'False
  10.    Height          =   690
  11.    Icon            =   CLIPPRNT.FRX:0000
  12.    Left            =   2760
  13.    LinkTopic       =   "Form1"
  14.    MaxButton       =   0   'False
  15.    ScaleHeight     =   0
  16.    ScaleWidth      =   2460
  17.    Top             =   4230
  18.    Width           =   2580
  19.    Begin Menu mnuPrint 
  20.       Caption         =   "&Print!"
  21.    End
  22.    Begin Menu mnuAbout 
  23.       Caption         =   "&About!"
  24.    End
  25. Option Explicit
  26. 'Margin values
  27. Const MARGIN_LEFT = 0
  28. Const MARGIN_RIGHT = 0
  29. Const MARGIN_TOP = 0
  30. Const MARGIN_BOTTOM = 0
  31. Sub Form_Load ()
  32.     'Centre the Form on the Screen
  33.     Move (screen.Width / 2) - (Width / 2), (screen.Height / 2) - (Height / 2)
  34. End Sub
  35. Sub mnuAbout_Click ()
  36.     frmAbout.Show 1 ' Modal
  37. End Sub
  38. Sub mnuPrint_Click ()
  39.     screen.MousePointer = 11 ' Hourglass
  40.     If Clipboard.GetFormat(2) Or Clipboard.GetFormat(3) Or Clipboard.GetFormat(8) Then
  41.         'We have a picture ( either a Metafile WMF or a Bitmap BMP/DIB )
  42.         Load frmBkground
  43.         'put the clipboard picutre on the form itself
  44.         frmBkground.Picture = Clipboard.GetData()
  45.         'Show the Form (note that the form will be maximized
  46.         frmBkground.Show
  47.         ' Let Windows catch up
  48.         DoEvents
  49.         ' ... and then print the form. easy eh?
  50.         frmBkground.PrintForm
  51.         Unload frmBkground
  52.     ElseIf Clipboard.GetFormat(1) Then
  53.         'We have text
  54.         PrintText Clipboard.GetText()
  55.     Else
  56.         'No picture or Text to display ( Must be nothing or something strange )
  57.         MsgBox "The clipboard does not contain a picture or text", 48, "Clipboard Printer"
  58.     End If
  59.     screen.MousePointer = 0 ' Default
  60.     ' Let Windows catch up
  61.     DoEvents
  62. End Sub
  63. '******************************************************
  64. '* Procedure    : PrintText
  65. '*-----------------------------------------------------
  66. '* Parameters   : text
  67. '*-----------------------------------------------------
  68. '* Returns      : none
  69. '*-----------------------------------------------------
  70. '* Prints a piece of text to the printer with headers
  71. '* footers, margins and full word wrap.
  72. '******************************************************
  73. Sub PrintText (text As String)
  74.     Dim i As Integer, j As Integer, currWord As String
  75.     i = 1
  76.     'Print text, word-wrapping as we go
  77.     Do Until i > Len(text)
  78.         'Get next word
  79.         currWord = ""
  80.         Do Until i > Len(text) Or Mid$(text, i, 1) <= " "
  81.             currWord = currWord & Mid$(text, i, 1)
  82.             i = i + 1
  83.         Loop
  84.         'Check if word will fit on this line
  85.         If (Printer.CurrentX + Printer.TextWidth(currWord)) > (Printer.ScaleWidth - MARGIN_RIGHT) Then
  86.             'Send carriage-return line-feed to printer
  87.             Printer.Print "" '& Chr$(187)
  88.             'Check if we need to start a new page
  89.             If Printer.CurrentY > (Printer.ScaleHeight - MARGIN_BOTTOM) Then
  90.                 Printer.NewPage
  91.                 Printer.CurrentX = MARGIN_LEFT
  92.                 Printer.CurrentY = Printer.ScaleHeight - (MARGIN_BOTTOM / 2)
  93.             Else
  94.                 Printer.CurrentX = MARGIN_LEFT
  95.             End If
  96.         End If
  97.         'Print this word
  98.         Printer.Print currWord;
  99.         'Process whitespace and any control characters
  100.         Do Until i > Len(text) Or Mid$(text, i, 1) > " "
  101.             Select Case Mid$(text, i, 1)
  102.                 Case " "        'Space
  103.                     Printer.Print " ";
  104.                 Case Chr$(10)   'Line-feed
  105.                     'Send carriage-return line-feed to printer
  106.                     Printer.Print
  107.         
  108.                     'Check if we need to start a new page
  109.                     If Printer.CurrentY > (Printer.ScaleHeight - MARGIN_BOTTOM) Then
  110.                         Printer.NewPage
  111.                         Printer.CurrentX = MARGIN_LEFT
  112.                         Printer.CurrentY = Printer.ScaleHeight - (MARGIN_BOTTOM / 2)
  113.                     Else
  114.                         Printer.CurrentX = MARGIN_LEFT
  115.                     End If
  116.                 Case Chr$(9)    'Tab
  117.                     j = (Printer.CurrentX - MARGIN_LEFT) / Printer.TextWidth("0")
  118.                     j = j + (10 - (j Mod 10))
  119.                     Printer.CurrentX = MARGIN_LEFT + (j * Printer.TextWidth("0"))
  120.                 Case Else       'Ignore other characters
  121.             End Select
  122.             i = i + 1
  123.         Loop
  124.     Loop
  125.     Printer.EndDoc
  126.     screen.MousePointer = 0     'Default
  127. End Sub
  128.