Hallo Solid-Edger
Habe ein Programmiertechnisches Problem
Ich und VB6 oder VB6 und VB.Net vertragen sich nicht so
Versuche Beispiel um ein EMF vom Clipboard auf einem Drucker auszudrucken.
Das untenstehende Beispiel ist von VB6 und funktioniert dort soweit.
Wie kriege ich das in Vb.Net 2008 hin. Alle meine Versuche scheiterten.
Ins Clipboard bring ich die Zeichnung noch, aber Drucken is nix.
Wäre um einen Tip, Codebeispiel sehr dankbar.
Freundliche Grüsse
Heinz
Private Sub PrintBtn_Click()
'This Sub is called when the "Print Active Sheet" button is clicked.
'Here, we get the control's active sheet to copy its enhanced
'metafile (EMF) into the system clipboard. We then read this EMF into
'a "Picture" object. Finally, we call our procedure, PrintDrawing, to print
'the picture.
Dim sts As Boolean
Dim PicObj As Picture
Dim AspectRatio As Double
Dim BnWPrint As Boolean
' First check if a draft file has been opened
If (SEDraftX1.ReadyState <> 4) Then
MsgBox (" A SE draft file has to be open")
Exit Sub
End If
'Show the hour-glass cursor
OldMousePointer = Form1.MousePointer
Form1.MousePointer = vbHourglass
AspectRatio = 1#
If (CheckBnWPrint.Value = 1) Then
BnWPrint = True
Else
BnWPrint = False
End If
Call SEDraftX1.ActiveSheet.CopyEMFToClipboard(AspectRatio, BnWPrint)
sts = Clipboard.GetFormat(vbCFMetafile)
If (sts = True) Then
Set PicObj = Clipboard.GetData(vbCFMetafile)
PrintDrawing PicObj, Printer, SEDraftX1.ActiveSheet.Name, AspectRatio
End If
'Restore the old cursor
Form1.MousePointer = OldMousePointer
End Sub
Sub PrintDrawing(PicObj As Picture, Device As Printer, Name As String, AspectRatio As Double)
'This Sub takes in a picture object and sends it to the printer object
'(2nd parameter) for printing.
'By using the width and height information of the picture and the printer
'device we fit the picture to the paper. Also, we set the paper orientation
'to landscape
Dim LeftMargin As Single
Dim TopMargin As Single
Dim PaperWidth As Single
Dim PaperHeight As Single
Dim PicWidth As Single
Dim PicHeight As Single
Dim PaperRatio As Double
Dim PicRatio As Double
Dim OldFontSize As Integer
'Set paper size to A4
'Device.PaperSize = vbPRPSA4 'UNCOMMENT AND MODIFY THIS LINE TO SET DESIRED PAPER SIZE
'Set paper orientation to landscape.
Device.Orientation = vbPRORLandscape
'Calculate the Left and Top margins (in TWIPS)
LeftMargin = 1000
TopMargin = LeftMargin
'Calculate the actual drawing area on the page (in TWIPS)
PaperWidth = Device.Width - LeftMargin * 2
PaperHeight = Device.Height - TopMargin * 2
'To maintain the aspect ratio re-calculate the paper width or height
PaperRatio = Device.Width / Device.Height
'PicRatio = PicObj.Width / PicObj.Height
PicRatio = AspectRatio
If (PaperRatio >= PicRatio) Then
PaperWidth = PaperHeight * PicRatio
Else
PaperHeight = PaperWidth / PicRatio
End If
'Convert Picture size from HIMETRIC to TWIPS
PicWidth = 567 * (PicObj.Width / 1000)
PicHeight = 567 * (PicObj.Height / 1000)
'Print the drawing
Device.PaintPicture PicObj, LeftMargin, TopMargin, PaperWidth, PaperHeight, 0, 0, PicWidth, PicHeight
Device.EndDoc
End Sub
Eine Antwort auf diesen Beitrag verfassen (mit Zitat/Zitat des Beitrags) IP