Results 1 to 6 of 6

Thread: Displaying Text Box Contents

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Posts
    30

    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]

  2. #2
    NicoVB
    Guest

    RE

    Maybe you can export it to WORD!! Isn't that better?

  3. #3
    New Member
    Join Date
    Jan 2002
    Location
    Kansas
    Posts
    11

    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

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Posts
    30
    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]

  5. #5
    New Member
    Join Date
    Jan 2002
    Location
    Kansas
    Posts
    11

    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

  6. #6

    Thread Starter
    Junior Member
    Join Date
    Aug 2001
    Posts
    30

    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
  •  



Click Here to Expand Forum to Full Width