vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
NEU! sevCoolbar 3.0 - Professionelle Toolbars im modernen Design!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

Fortgeschrittene Programmierung
Re: Drucken mit VB (Teil 3) 
Autor: BasTler
Datum: 02.05.05 13:23

Sub Form_Print(localname As Form)
  Const IDOK = 1  ' OK button pressed
 
  On Error GoTo Form_Print_Fehler
  If MsgHardcopy() = IDOK Then
    If (Forms.Count - 1) > 1 Then
       If localname.WindowState = vbMinimized Then
         localname.WindowState = vbNormal
         DoEvents
       End If
      ' The ScaleMode must be set to pixels for the CaptureWindow
      ' routine to print correctly.
      Printer.ScaleMode = vbPixels
      ' Change MousePointer to an hourglass.
      Screen.MousePointer = vbHourglass
      ' Initialize the printer.
      Printer.Print ""
      ' Copy the image of the form to the printer.
      PrintPictureToFitPage Printer, CaptureWindow(localname.hwnd, 0, 0, _
        localname.ScaleX(localname.Width, vbTwips, vbPixels), _
        localname.ScaleY(localname.Height, vbTwips, vbPixels))
      Printer.EndDoc
      Screen.MousePointer = vbDefault
    End If
  End If
  Exit Sub
 
Form_Print_Fehler:
  Error_Log "Form_Print", Err, Erl
End Sub
 
Public Sub PrintPictureToFitPage(Prn As Printer, pic As Picture)
  Const vbHiMetric As Integer = 8
  Dim ret As Integer
  Dim Pcnt As Integer, I As Integer
  Dim PicRatio As Double, PrnWidth As Double
  Dim PrnHeight As Double, PrnRatio As Double
  Dim PrnPicWidth As Double, PrnPicHeight As Double
  Dim Zeile As String
 
  On Error GoTo PrintPicture_Fehler
  ' The following is an example of mixing text with bitmap.
  Pcnt = Prn.FontCount - 1
  For I = 0 To Pcnt ' Determine number of fonts.
    If Prn.Fonts(I) = "Courier" Then Printer.FontName = "Courier"
    If Prn.Fonts(I) = "Arial" Then
      Prn.FontName = "Arial"
      I = Prn.FontCount
    End If
    If Prn.Fonts(I) = "Helv" Then
      Prn.FontName = "Helv"
      I = Prn.FontCount
    End If
  Next I
  Prn.FontSize = 24
  Prn.FontBold = True
  If Prn.FontName = "Courier" Then
    Prn.Print "Hardcopy" 
  End If
  Prn.FontSize = 12
  Prn.FontBold = False
  Prn.Print Date & Space$(4) & Left$(Time$, 5)
 
  ' Calculate device independent Width-to-Height ratio for picture.
  PicRatio = pic.Width / pic.Height
 
  ' Calculate the dimentions of the printable area in HiMetric.
  PrnWidth = Prn.ScaleX(Prn.ScaleWidth, Prn.ScaleMode, vbHiMetric) * 1.6
  PrnHeight = Prn.ScaleY(Prn.ScaleHeight, Prn.ScaleMode, vbHiMetric) * 1.6
 
  ' Calculate device independent Width to Height ratio for printer.
  PrnRatio = PrnWidth / PrnHeight
 
  ' Scale the output to the printable area.
  If PicRatio >= PrnRatio Then
    ' Scale picture to fit full width of printable area.
    PrnPicWidth = Prn.ScaleX(Prn.Width, vbHiMetric, Prn.ScaleMode) * 1.6
    PrnPicHeight = Prn.ScaleY(Prn.Width / PicRatio, vbHiMetric, Prn.ScaleMode) _
      * 1.6
  Else
    ' Scale picture to fit full height of printable area.
    PrnPicHeight = Prn.ScaleY(Prn.Height, vbHiMetric, Prn.ScaleMode)
    PrnPicWidth = Prn.ScaleX(Prn.Height * PicRatio, vbHiMetric, Prn.ScaleMode)
  End If
 
  ' Print the picture using the PaintPicture method.
  Prn.PaintPicture pic, 0, 450, PrnPicWidth, PrnPicHeight
  Exit Sub
 
PrintPicture_Fehler:
  Select Case Err
    Case 480:
      MsgBox "Fehler 480: beim Ausdruck der Maske aufgetreten.", 48, "Hardcopy"
    Case 482:
      If MsgBox("Fehler 482: Drucker nicht bereit.", 5, "Hardcopy") = 4 Then
        Resume
      Else
        Screen.MousePointer = vbDefault     ' Voreinstellung
      End If
    Case Else:
      Error_Log "PrintPicture", Err
  End Select
End Sub
Die Procedure liegt in der MDI-Form die auch den Druck-Button enthält.
Private Sub CSCmdDrucken_Click()
  Form_Print ActiveForm
  Text1.SetFocus
End Sub
Gruß BasTler
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Drucken mit VB1.249AWenig02.05.05 08:30
Re: Drucken mit VB1.122BasTler02.05.05 13:19
Re: Drucken mit VB (Teil 2)765BasTler02.05.05 13:22
Re: Drucken mit VB (Teil 3)912BasTler02.05.05 13:23
Re: Drucken mit VB (Teil 3)738AWenig02.05.05 13:36
Re: Drucken mit VB791BasTler02.05.05 14:37
Re: Drucken mit VB (Teil 3)1.588Zardoz02.05.05 17:08
Re: Drucken mit VB (Teil 3)710AWenig02.05.05 19:56

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel