visual basic printen

Status
Niet open voor verdere reacties.

mastermindzh

Verenigingslid
Lid geworden
10 dec 2008
Berichten
4.993
hoi allemaal,
ik maak een tabbed notepad maar ik weet de printcode niet :confused: heb alles al gevonden (font enzo) door veel proberen en veel moeite...

print wil niet werken :confused:
nu dacht ik aan

Code:
My.Computer.FileSystem.WriteAllText("C:\Users\%username%\Desktop\print.txt", TabControl1.Text, False)
        WebBrowser1.Navigate("C:\Users\%username%\Desktop\print.txt")
        WebBrowser1.ShowPrintDialog()

omdat iemand mij een filmpje op youtube erover liet zien :p maar dat deed het niet :confused:

ook op de manier van copy en cut ging het niet
Code:
CType(TabControl1.SelectedTab.Controls.Item(0), RichTextBox).Cut()

deze manier,

dus mijn vraag, zijn er nog andere idee-en?
 
Mischien kan je hier iets mee wat print mogelijkheden

Code:
Imports System.Drawing.Printing
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

#End Region

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Text = "Programmers have undergone a major change in many years of "
        'filling the richtextbox with some text that can be used readily
    End Sub

    Private Sub PrintToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem.Click
        If PrintDialog1.ShowDialog = DialogResult.OK Then
            'showDialog method makes the dialog box visible at run time
            PrintDocument1.Print()
        End If
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        'PrintPage is the foundational printing event. This event gets fired for every 
        ' page that will be printed
        Static intCurrentChar As Int32
        ' declaring a static variable to hold the position of the last printed char
        Dim font As New Font("Verdana", 14)
        ' initializing the font to be used for printing
        Dim PrintAreaHeight, PrintAreaWidth, marginLeft, marginTop As Int32
        With PrintDocument1.DefaultPageSettings
            ' initializing local variables that contain the bounds of the printing area rectangle
            PrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
            PrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
            ' initializing local variables to hold margin values that will serve
            ' as the X and Y coordinates for the upper left corner of the printing 
            ' area rectangle.
            marginLeft = .Margins.Left
            marginTop = .Margins.Top
            ' X and Y coordinate
        End With

        If PrintDocument1.DefaultPageSettings.Landscape Then
            Dim intTemp As Int32
            intTemp = PrintAreaHeight
            PrintAreaHeight = PrintAreaWidth
            PrintAreaWidth = intTemp
            ' if the user selects landscape mode, swap the printing area height and width
        End If

        Dim intLineCount As Int32 = CInt(PrintAreaHeight / font.Height)
        ' calculating the total number of lines in the document based on the height of
        ' the printing area and the height of the font
        Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, PrintAreaWidth, PrintAreaHeight)
        ' initializing the rectangle structure that defines the printing area
        Dim fmt As New StringFormat(StringFormatFlags.LineLimit)
        'instantiating the StringFormat class, which encapsulates text layout information
        Dim intLinesFilled, intCharsFitted As Int32
        e.Graphics.MeasureString(Mid(DataGridView1.ToString, intCurrentChar + 1), font, New SizeF(PrintAreaWidth, PrintAreaHeight), fmt, intCharsFitted, intLinesFilled)
        ' calling MeasureString to determine the number of characters that will fit in
        ' the printing area rectangle
        e.Graphics.DrawString(Mid(DataGridView1.ToString, intCurrentChar + 1), font, Brushes.Black, rectPrintingArea, fmt)
        ' print the text to the page
        intCurrentChar += intCharsFitted
        'advancing the current char to the last char printed on this page
        'HasMorePages tells the printing module whether another PrintPage event should be fired

        e.HasMorePages = False
        intCurrentChar = 0

    End Sub

    Private Sub PrintToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintToolStripMenuItem1.Click
        Try
            PrintPreviewDialog1.ShowDialog()
        Catch es As Exception
            MessageBox.Show(es.Message)
        End Try
    End Sub

    Private Sub PagesetupToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PagesetupToolStripMenuItem.Click
        With PageSetupDialog1
            .PageSettings = PrintDocument1.DefaultPageSettings
        End With
        Try
            If PageSetupDialog1.ShowDialog = DialogResult.OK Then
                PrintDocument1.DefaultPageSettings = PageSetupDialog1.PageSettings
            End If
        Catch es As Exception
            MessageBox.Show(es.Message)
        End Try
    End Sub

    Private Sub PPControlToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PPControlToolStripMenuItem.Click
        Try
            PrintPreviewControl1.Document = PrintDocument1
        Catch es As Exception
            MessageBox.Show(es.Message)
        End Try
    End Sub

   
    Private Sub PrintDataToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PrintDataToolStripMenuItem.Click
        Try
            PrintPreviewControl1.Document = PrintDocument1

            PrintPreviewDialog1.ShowDialog()
        Catch es As Exception
            MessageBox.Show(es.Message)
        End Try
    End Sub
End Class
Let wel Zet bij Properties van de PrintPreviewDialog1 de waarde PrintDocument1
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan