|
-
Jan 3rd, 2002, 11:18 PM
#1
Thread Starter
Junior Member
Displaying Text Box Contents
Hi - I've got words, numbers etc... in about 15 different text boxes on a form. I'd like to print this data, and I think I understand how to do that, but getting this data to a printable form is the problem. It's spread out over 15 different text boxes and I'd just like to organize this into a nice looking sheet to print.
This data is being supplied from an XML source, not that I think that'll help, but perhaps. I thought about using crystal reports, but I've no idea how to use that. Anyone have any suggestions on turning textbox.text into a nice printable fashion?
Thanks!!
Reid Plumbo
[email protected]
-
Jan 4th, 2002, 08:23 AM
#2
RE
Maybe you can export it to WORD!! Isn't that better?
-
Jan 4th, 2002, 10:27 AM
#3
New Member
Printing
There is a handy "print document" class (new to .NET?) that will allow you to print without having to export to Word or Crystal reports. This class is System.Drawing.Printing.PrintDocument
You must declare this object withevents:
Private Withevents m_objPrintDoc As New System.Drawing.Printing.PrintDocument
In the sub that you want to do the printing from, say
Call m_objPrintDoc.Print
This is not some synchronous call to a function that's going to print who knows what before it returns control to the next line of the sub here. You have control over what is being printed after you tell the print document object to begin printing (this isn't exactly obvious, but it works very well. Because you have declared this object withevents, you can create a sub to handle m_objPrintDoc.PrintPage. As an example, this is the code to print a screenshot (very handy!) stretched (though without keeping aspect ratio) on the bounds of the drawing surface.
Private Sub m_objPrintDoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles m_objPrintDoc.PrintPage
Call e.Graphics.DrawImage (m_imgScreenShot, e.MarginBounds.Top, e.MarginBounds.Left, e.MarginBounds.Width, e.MarginBounds.Height)
End Sub
This function will fire for every page that the print document object requires printing for. Once again, this is misleading as to make one think that the content is predefined. In this case, I only have one page, but I could tell the print document object to print again by saying: e.HasMorePages = True, which would call this function again after "End Sub".
For text, use the drawtext method to put the text on the drawing canvas.
Tada!! 
--Johnny
-
Jan 4th, 2002, 11:15 AM
#4
Thread Starter
Junior Member
Ok, I like what you've started me on, it looks promising. Can we put this into context to help me further?
Let's say that I've got a button named cmdPrint, when pushed it will print the text of txtEmailAddress. How can I adapt your code to perform this? Is there anyway I can view this layout before printing?
Thanks!!
Reid Plumbo
[email protected]
-
Jan 4th, 2002, 11:21 AM
#5
New Member
DrawText
Well, instead of saying e.Graphics.DrawImage, say e.Graphics.DrawText. That's all that changes.
I think there may be a print preview option in the System.Drawing.Printing namespace, but if not, you can use simply use the drawing to draw the preview in your own window. Those graphics functions aren't specific to printing.
--Johnny
-
Jan 7th, 2002, 12:02 AM
#6
Thread Starter
Junior Member
Problems
Okay, I've tried to do "DrawText" in place of "DrawImage" to no avail. It doesn't seem to be part of the PrintDocument class. You know what you're doing, so I'd like to ask you a question, or rather show me an example.
Can you show me some code that prints the contents of:
txtEmail
txtFirstName
txtLast Name
Let's say the button to do this is simply called cmdPrint. I'm attempting to produce results that look like this:
[email protected]
Reid
Plumbo
If you could use these specific names in an example, that'd help me out.
Thank you!!!
Sincerely, and most graciously,
Reid Plumbo
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|