|
-
May 29th, 2003, 03:06 PM
#1
Thread Starter
Lively Member
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
-
May 29th, 2003, 03:38 PM
#2
Fanatic Member
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).
-
May 30th, 2003, 12:50 PM
#3
I wonder how many charact
Getting text to stay within a box is no biggie really... with the
help of a StringFormat instance...
VB Code:
Imports System.Text
Imports System.Drawing
Public Sub DrawInfo(ByRef g As Graphics, ByRef b As Brush, ByRef f As Font, _
ByVal s As String, ByVal [width] As Integer, ByVal [height] As Integer)
'you can pass a single-line string, but obviously this
'sub is useful because it can print multi-line strings
'wrapping words all the way through until it hits the
'boundary of the height parameter, at which point
'it clips the rest of the text
'You could implement measureString to internally adjust the size
'of the rectangle height if you wish... most reports just clip though
'Dim CR As Char() = {ChrW(13), ChrW(10)}
'Dim s As New StringBuilder()
's.Append("Line 1")
's.Append(CR)
's.Append("Line 2")
'DrawInfo(mygraphics,myBrush,myFont,s.ToString,1000,400)
Dim strFormat As New StringFormat()
strFormat.Alignment = StringAlignment.Near
strFormat.LineAlignment = StringAlignment.Near
strFormat.Trimming = StringTrimming.Word
Dim myrectF As New RectangleF(0, 0, [width], [height])
'the key here is passing our rectangle boundary (myrectF),
'and our stringFormatter ( strFormat) into Graphics.DrawString
g.DrawString(s, f, b, myrectF, strFormat)
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|