Print Document and PrintPreviewDialog Questions

S

Slonocode

First a background on what I'm trying to achieve. I'm writing a small
utitily that will paste the contents of the clipboard(a mailing address)
into a textbox. Then the contents of the textbox will be sent to the
printer and printed on a label. The label is 4" high by 5.625" wide and
tractor fed in bulk. The printer is dot matrix and physically connected to
another machine but shared and set as default on the machine running the
utility.

ABOUT THE PRINTDOCUMENT OBJECT:
When instantiating where does it get its defaultpagesettings and
printersettings? I am assuming from the printer properties of the actual
machine?

I created a new form in the server properties on the machine for the label.

Here is my printdocument code

Private Sub pd_PrintPage(ByVal sender As System.Object, ByVal e As
System.Drawing.Printing.PrintPageEventArgs)

Dim fnt As Font = Me.txtAddress.Font

Dim brush As New SolidBrush(Color.Black)

Dim s As String = Me.txtAddress.Text

Dim x As Single = e.MarginBounds.Left

Dim y As Single = e.MarginBounds.Top

e.Graphics.DrawString(s, fnt, brush, x, y)

e.HasMorePages = False

End Sub



ABOUT THE PRINTPREVIEWDIALOG OBJECT:
I can't seem to get the print preview to accurately reflect the label. It
always shows a letter sized preview and the text is too small to read.
Which leads me to believe that my actual print document is probably letter
sized since it just draws the printdocument. Although the form feed on the
printer works correctly for the label. So needless to say I'm somewhat
confused.

Here is the printpreview code

Private Sub btnPrintPreview_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnPrintPreview.Click

Dim ppdlg As PrintPreviewDialog = New PrintPreviewDialog()

With ppdlg

..Document = pd

..WindowState = FormWindowState.Normal

..ShowDialog(Me)

End With

End Sub



Thanks for any assistance

--Sloncode
 
S

Slonocode

Well I fixed part of the problem but created another.

I defined a custom paper size in the code and set the
printdocument.defaultpagesettings = customsize.

here is that code:

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

pd.DocumentName = "Address Label"

AddHandler pd.PrintPage, AddressOf pd_PrintPage

Dim CustomSize As Printing.PaperSize = New Printing.PaperSize("USPS Label
228C", 563, 400)

pd.DefaultPageSettings.PaperSize = CustomSize

Dim margins As New Margins(80, 38, 185, 38)

pd.DefaultPageSettings.Margins = margins

End Sub



This however created a new problem. The formfeed doesnt work correctly
anymore. It prints the text onto the label but then feeds through 1.5 blank
labels and isn't in postion for the next printing.



Any help?

--Slonocode
 
S

Slonocode

Anyone?

Perhaps if I asked more succinctly?

1. How are the printer settings on the machine related to the
printdocument's printersettings?
2. Does anyone have an example of creating a custom printdocument obj
completely in code?
3. Should a completely customized printdocument obj be able to completely
control the printer?


I'm not trying to be rude or pushy. I just thought that maybe my other
posts in this thread were perhaps too long and not clear enough to elicit an
asnwer.

Thanks
--Sloncode
 
H

Herfried K. Wagner [MVP]

* "Slonocode said:
Perhaps if I asked more succinctly?

1. How are the printer settings on the machine related to the
printdocument's printersettings?
2. Does anyone have an example of creating a custom printdocument obj
completely in code?
3. Should a completely customized printdocument obj be able to completely
control the printer?

I'm not trying to be rude or pushy. I just thought that maybe my other
posts in this thread were perhaps too long and not clear enough to elicit an
asnwer.

Maybe this helps:

<http://www.mvps.org/dotnet/dotnet/samples/printing/downloads/PrintFramework.zip>

Sorry, comments are only available in German.

;-)
 
S

Slonocode

I have looked at the sample code and comments or no comments I don't see
anything relating to a custom sized printdocument.

I have created a new form in the server settings of my machine. 4" height
5.625" wide and set every conceivable setting to use this as default. When
I create a new printdocument with a page settings dialog routine and I open
the dialog it is set to use the form I created. But the printpreview dialog
continues to show a letter sized document.

If I play around with the papersize properties I can get the print preview
to show correctly but then the form feed of the printer does not work
correctly.

I have also posted my problem to the drawing group but got no response(that
group doesn't appear to get heavy traffic though either).

Herfried I also wasn't sure how to interpret your response. As I was pretty
sure you knew I had already seen that code. Either you were implying that
the answer was contained in it, in which case I don't see it. Or you were
implying that you don't know the answer and kind of tounge in cheeck letting
me know that.

I have googled until I can't google anymore trying to find info on this but
am coming up empty.

--Slonocode
 
H

Herfried K. Wagner [MVP]

* "Slonocode said:
Herfried I also wasn't sure how to interpret your response. As I was pretty
sure you knew I had already seen that code. Either you were implying that
the answer was contained in it, in which case I don't see it. Or you were
implying that you don't know the answer and kind of tounge in cheeck letting
me know that.

Sorry, I thought you had problems understanding basic printing
techniques.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top