Toon posts:

[vb.net] printdocument -> wordwrap

Pagina: 1
Acties:

Verwijderd

Topicstarter
Ik ben een beetje aan het rotzooien met het printen van documenten in vb.net. Het gaat helemaal goed, behalve een ding, en dat is de wordwrap. Lange zinnen komen dus niet helemaal op het papier te staan. (wordwrap is dus uit) Maar de wordwrap moet aan.

Hoe kan ik wordwrap aan zetten, of is er een andere mogelijk om ervoor te zorgen dat de zinnen worden afgekapt en naar de volgende regel gaan?

  • pjonk
  • Registratie: November 2000
  • Laatst online: 29-12-2025
De printer moet intelligent genoeg zijn om dit zelf te wrappen. Heb je wel een rightmargin ingesteld? Post anders wat code.

Disclaimer
* pjonk kent alleen VB6 en niet VB.net

It’s nice to be important but it’s more important to be nice


Verwijderd

Topicstarter
Aanroepen van het printen:
Visual Basic .NET:
1
Printer.Print()


De functie die het uitprint:
Visual Basic .NET:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
    Private Sub Printer_PrintPage(ByVal sender As Object, ByVal e As _
    System.Drawing.Printing.PrintPageEventArgs) Handles Printer.PrintPage
        Dim fileToPrint As New System.IO.StreamReader(Application.StartupPath & "Filestemp.txt")
        Dim printFont As New System.Drawing.Font("Microsoft Sans Serif", 10)
        Dim linesPerPage As Single = 0
        Dim yPos As Single = 0
        Dim count As Integer = 0
        Dim leftMargin As Single = 10
        Dim topMargin As Single = 10
        Dim line As String = Nothing
        linesPerPage = e.MarginBounds.Height / printFont.GetHeight(e.Graphics)

        While count < linesPerPage
            line = fileToPrint.ReadLine()
            If line Is Nothing Then Exit While
            yPos = topMargin + count * printFont.GetHeight(e.Graphics)
            e.Graphics.DrawString(line, printFont, Brushes.Black, leftMargin, _
            yPos, New StringFormat())
            count += 1
        End While
        If Not (line Is Nothing) Then
            e.HasMorePages = True
        End If
        fileToPrint.Close()
    End Sub


Het bovenstaande stuk komt bijna letterlijk van MSDN af.
En idd, de rightmargin staat niet ingesteld, maar ik kan niet vinden waar ik die moet instellen :/

[ Voor 3% gewijzigd door Verwijderd op 06-12-2003 19:27 ]


  • pjonk
  • Registratie: November 2000
  • Laatst online: 29-12-2025
Deze pagina al bekeken?
http://msdn.microsoft.com...ms/html/printwinforms.asp

Daar kom ik margin properties in het PrintPageEventArgs tegen e.MarginBounds.Left, e.MarginBounds.Right, e.MarginBounds.Top en e.MarginBounds.Left.Bottom.

In deze paragraaf in de URL staat volgens mij wat jij nodig hebt:
Outputting Text
Regardless of the underlying data type of your fields, you will be outputting text for every column of your report and for your headers and footers, all through the DrawString method of the Graphics class. When drawing text for use in a report, you often have to deal with size and positioning restrictions, and DrawString has provided the LayoutRectangle parameter for exactly that reason. By specifying a LayoutRectangle, you are forcing the text into a specific area, with automatic word wrapping and other features controllable through the StringFormat parameter.

[ Voor 55% gewijzigd door pjonk op 06-12-2003 19:40 ]

It’s nice to be important but it’s more important to be nice


Verwijderd

Topicstarter
Bedankt, daar moet het zeker wel mee lukken.