I'm trying to print the form in visual studio when you press the P key but when its working but it keeps degrading the quality of the image/form and i don't know how to resize the form size in the printing.
this is the form i want to print
this is the degraded quality after i print the image
Private Sub IDPrint_KeyPress(sender As Object, e As KeyPressEventArgs) Handles MyBase.KeyPress
If e.KeyChar = "p" OrElse e.KeyChar = "P" Then
PrintDialog1.ShowDialog()
PrintForm1.PrinterSettings = PrintDialog1.PrinterSettings
PrintForm1.Print()
End If
End Sub
Power Pack Printform control is simply a bitmap copy of the screen. Since printers probably have a higher pixel resolution than monitors, the image you want to print will be stretched and appear fuzzy.
Considering Power Pack Printform is out of date and limited, I suggest you use the PrintDocument component to print from a Windows Form.
Here's the document you can refer to: How to: Print a Windows Form
Related
I'm new to this. I'm using Visual Basic from Visual Studio 2017 Community, and I have an issue printing a form.
If i use this:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Me.PrintForm1.PrintAction = Printing.PrintAction.PrintToPreview
Me.PrintForm1.Print()
End Sub
on my regular printer it displays the form fine, but i needed to print the form on a label. When I change the printer to my Zebra printer, it does not display anything. Can anyone help me?
I am trying (and failing) right now to print a Windows Form as a PDF File in VB.Net
Now I know from doing some research that VB.Net does not have any built in function which could allow me to do this without using a third party application.
My way to get around this, was to attempt to print my Form using a PDF Printer, since logically that should work no? My issue is getting that to work properly.
This is currently my code for attempting to print:
Private Sub SelectPrinterThenPrint()
Dim PrintersDialog As New PrintDialog()
If PrintersDialog.SHowDialog(Me) = System.Forms.DialogResult.OK Then
Try
p_Document = New PrintDocument()
PrintersDialog.Document = p_Document
AddHandler p_Document.PrintPage, AddressOf HandleOnPrintPage
Catch ex As Exception
End Try
End If
End Sub
Private Sub HandleOnPrintPage(ByVal sender As Object, ByVal e As PrintPageEventArgs) Handles p_Document.PrintPage
Dim MorePagesPending = False
Dim bmp As New Bitmap(pnlContainer.Width, pnlContainer.Height)
pnlContainer.DrawToBitmap(bmp, pnlContainer.ClientRectangle)
e.Graphics.DrawImage(bmp, New Point(0,0))
If MorePagesPending Then
e.HasMorePages = True
Else
e.HasMorePages = False
End If
End Sub
The SelectPrinterThenPrint() method is called when a button on my Form is clicked. Right now I am having two issues.
1) I don't know how to setup where the file gets saved. The Print Dialog opens, and I get to select my PDF Printer, but it doesn't let me set a filename. So how do I set the filename I want to be printing to?
2) Because I can't tell if the file is actually being saved, I can't tell if I am actually setting up the print properly or not. I am trying to print the entire contents of a panel, which holds all the elements I want on my PDF file. One thing I am unsure about however, is that the form the panel is displayed in, is not the same size as the panel. The Form the panel is in has the same width, but not the same height, with the form being set up for auto scrolling. Will I get the whole Panel to print? Or just the part the is visible in the form at the time of printing?
Can anyone help me.
Do I need to send printer commands when printing through a windows driver?
I am writing a windows forms application which prints out information on a label printer. This information contains an image which has a title and a barcode on it. I can create the image ok, but when I try to send it to the printer it prints completely wrong!
The Esc commands are normally handled through the Windows Driver. Here's rough example on how to print an image. You initialize PrintDocument, then use the Print method to start printing. Windows then calls the PrintPage handler, which draws on e.Graphics. e.Graphics is effectively the printer page.
Dim pd As PrintDocument
AddHandler pd.PrintPage, AddressOf printPage
' assign pd properties
pd.Print
Sub printPage(ByVal sender As Object, ByVal e As PrintPageEventArgs)
' assign img, set rectangle, determine number of pages, etc.
e.Graphics.DrawImage(img, rectangle) ' essentially draws on the printer page
e.HasMorePages = ...
end sub
I'm developing a tool for easy picture printing with a canon selpy cp800. The Image is printed with the following methods:
Private Sub BtnPrintClick(sender As Object, e As System.EventArgs) Handles ptnPrint.Click
If PrintDialog1.ShowDialog() = DialogResult.OK Then
pdPrintImage.Print()
End If
End Sub
Private Sub PdPrintImagePrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs) Handles pdPrintImage.PrintPage
e.Graphics.DrawImage(_dPictures(_sPictures(_iActiveImage)).Picture, e.Graphics.VisibleClipBounds)
End Sub
_dPictures(_sPictures(_iActiveImage)).Picture --> object of the type image
I didn't do anything with this image. It's only loaded with the Image.FromFile() method.
Within the following image you can see my problem. This is a scan of the image printed with this method (top) and a scan of the same image printed with the windows picture viewer. You see, the first image you see the tonal errors in the background and the shadows.
Has anyone an idea to fix this?
If it isn't a bit-depth issue as Boo mentioned, it might help to set one or both of these
e.Graphics.InterpolationMode = Drawing2D.InterpolationMode.HighQualityBicubic
e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
before doing the .DrawImage.
the best quality I achieved as follows:
1) I put a picture into pdf using components iTextsharp.
2) print the pdf
Does anyone have any code suggestions or samples for printing photos (BMP or TIFF or JPEG), using Visual Basic or .NET framework?
VB6 and .NET handle printing quite differently. These examples are the bare minumum, just to give you an idea of the process.
In VB6 you control the printer step by step:
Private Sub PrintMyPicture()
'Place to store my picture
Dim myPicture As IPictureDisp
'Load the picture into the variable
Set myPicture = LoadPicture("C:\temp\myPictureFile.bmp")
'Draw the picture on the printer, just off the edge of the page
Printer.PaintPicture myPicture, 10, 10
'Done printing!
Printer.EndDoc
End Sub
Lo and behold, your picture will come out of the default printer. the PaintPicture method accepts width, height and a few other parameters to help get the image to fit, and the Printer object gives you all sorts of info about the printer.
In .Net it's kind of the other way around. You start printing, and the printer will raise an event for each page until you tell it to stop. Every page event gives you as graphics object upon which you can draw using all of the standard System.Drawing classes and methods:
'Class variable
Private WithEvents printer As System.Drawing.Printing.PrintDocument
' Kick off the printing process. This will cause the printer_PrintPage event chain to start firing.
Public Sub PrintMyPicture()
'Set up the printer
printer.PrinterSettings.PrinterName = "MyPrinterNameInPrintersAndFaxes"
printer.Print()
End Sub
'This event will keep firing while e.HasMorePages = True.
Private Sub printer_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles printer.PrintPage
'Load the picture
Dim myPicture As System.Drawing.Image = System.Drawing.Image.FromFile("C:\temp\myPictureFile.bmp")
'Print the Image. 'e' is the Print events that the printer provides. In e is a graphics object on hwich you can draw.
'10, 10 is the position to print the picture.
e.Graphics.DrawImage(myPicture, 10, 10)
'Clean up
myPicture.Dispose()
myPicture = Nothing
'Tell the printer that there are no more pages to print. This will cause the document to be finalised and come out of the printer.
e.HasMorePages = False
End Sub
Again, there are a lot more parameters in DrawImage and the PrintDocument objects.