Results 1 to 3 of 3

Thread: What is the best way to print a document in VB.Net ?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    68

    What is the best way to print a document in VB.Net ?

    I would like to print invoice from vb.net

    with information Customer, order detail , ...

    But using printing function from Vb seems to be very hard for a poor result.

    what are the other solution ?

    using a Word template and sending information via parameters ?

    exporting data to a file and opening Word with a macro for the importation of data and some VBA code ...

    Other product ?



    Thanks as usual

  2. #2
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Probably the "best" way to get form-looking printed output is to use Crystal Reports. Do you have it installed? Not sure if it comes with all version of VS.NET.

    If you don't have access Crystal Reports, then yes, other anoptions is to pipe your data to MS Word or MS Access (Access is probably the better choice if you're working with database info).

    You could also write your own printing code using graphical boxes drawn around the text you want to print, but getting the text to stay inside the boxes and have the boxes size themselves automatically etc. will be quite painful to do manually.

    Another option is to use the extended richtextbox control Martin Muller wrote (see this thread).

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    Getting text to stay within a box is no biggie really... with the
    help of a StringFormat instance...

    VB Code:
    1. Imports System.Text
    2. Imports System.Drawing
    3.  
    4.         Public Sub DrawInfo(ByRef g As Graphics, ByRef b As Brush, ByRef f As Font, _
    5. ByVal s As String, ByVal [width] As Integer, ByVal [height] As Integer)
    6.    
    7.         'you can pass a single-line string, but obviously this
    8.         'sub is useful because it can print multi-line strings
    9.         'wrapping words all the way through until it hits the
    10.         'boundary of the height parameter, at which point
    11.         'it clips the rest of the text
    12.         'You could implement measureString to internally adjust the size
    13.         'of the rectangle height if you wish... most reports just clip though
    14.  
    15.         'Dim CR As Char() = {ChrW(13), ChrW(10)}
    16.         'Dim s As New StringBuilder()
    17.          's.Append("Line 1")
    18.          's.Append(CR)
    19.          's.Append("Line 2")
    20.          'DrawInfo(mygraphics,myBrush,myFont,s.ToString,1000,400)
    21.        
    22.        
    23.  
    24.         Dim strFormat As New StringFormat()
    25.  
    26.         strFormat.Alignment = StringAlignment.Near
    27.         strFormat.LineAlignment = StringAlignment.Near
    28.         strFormat.Trimming = StringTrimming.Word
    29.         Dim myrectF As New RectangleF(0, 0, [width], [height])
    30.         'the key here is passing our rectangle boundary (myrectF),
    31.         'and our stringFormatter ( strFormat) into Graphics.DrawString
    32.         g.DrawString(s, f, b, myrectF, strFormat)
    33.      End Sub
    Last edited by nemaroller; May 30th, 2003 at 12:56 PM.

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