Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27333

VS 2010 Print chart problem

$
0
0
Hello,

I 'm trying to write e code to print (to printer) the results of some calculatios and a chart in the same paper. Since I could not do it, I've been doing a lot of research. I ended up with a piece of code from Microsoft, but it prints the chart in another page. I has not been able to get it fix to my need. That's the problem. Any help would be appreciated.

Here is my code:


HTML Code:

    Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click

        Dim res As DialogResult = Me.PrintDialog1.ShowDialog
        Dim Printer As PowerPacks.Printing.Compatibility.VB6.Printer
        Dim myfont As Font

        Printer = New PowerPacks.Printing.Compatibility.VB6.Printer

        If res = Windows.Forms.DialogResult.OK Then
            myfont = New System.Drawing.Font("Arial", 18, FontStyle.Bold)
            Printer.Orientation = 2

            'TITLE
            Printer.FillColor = RGB(0, 128, 0)
            Printer.ForeColor = RGB(255, 255, 255)
            Printer.DrawStyle = 0
            Printer.DrawWidth = 50
            Printer.Line(3900, 750, 12000, 1650, RGB(128, 0, 0), True)

            'PRINT TITLE
            Printer.ForeColor = RGB(50, 62, 26)
            Printer.Font = myfont
            Printer.CurrentX = ((Printer.ScaleWidth - Printer.TextWidth(Label1.Text)) \ 2)
            Printer.CurrentY = 1000
            Printer.Print(Label1.Text)

            'TITLE FRAME
            Printer.DrawWidth = 30
            Printer.Line(3000, 2300, 12900, 5000, RGB(128, 0, 0), True)

            'PRINT RESULTS LABELS
            myfont = New System.Drawing.Font("Arial", 12, FontStyle.Bold)

            Printer.Font = myfont
            Printer.CurrentY = 2800
            Printer.CurrentX = 3800
            Printer.Print(Label2.Text)

            Printer.CurrentY = 2800
            Printer.CurrentX = 8800
            Printer.Print(Label5.Text)

            Printer.CurrentY = 3500
            Printer.CurrentX = 3800
            Printer.Print(Label3.Text)

            Printer.CurrentY = 3500
            Printer.CurrentX = 8800
            Printer.Print(Label6.Text)

            Printer.CurrentY = 4200
            Printer.CurrentX = 3800
            Printer.Print(Label4.Text)

            Printer.CurrentY = 4200
            Printer.CurrentX = 8800
            Printer.Print(Label7.Text)

            'PRINT RESULTS FRAMES
            Printer.DrawWidth = 10

            Printer.Line(5150, 2750, 6750, 3150, RGB(128, 0, 0), True)
            Printer.Line(10500, 2750, 12100, 3150, RGB(128, 0, 0), True)

            Printer.Line(5150, 3450, 6750, 3850, RGB(128, 0, 0), True)
            Printer.Line(10500, 3450, 12100, 3850, RGB(128, 0, 0), True)

            Printer.Line(5150, 4150, 6750, 4550, RGB(128, 0, 0), True)
            Printer.Line(10500, 4150, 12100, 4550, RGB(128, 0, 0), True)

            'PRINT RESULTS
            myfont = New System.Drawing.Font("Arial", 12, FontStyle.Bold)
            Printer.ForeColor = RGB(0, 0, 0)

            Printer.Font = myfont
            Printer.CurrentY = 2800
            Printer.CurrentX = 5200
            Printer.Print(TextBox1.Text)

            Printer.CurrentY = 2800
            Printer.CurrentX = 10600
            Printer.Print(TextBox4.Text)

            Printer.CurrentY = 3500
            Printer.CurrentX = 5200
            Printer.Print(TextBox2.Text)

            Printer.CurrentY = 3500
            Printer.CurrentX = 10600
            Printer.Print(TextBox5.Text)

            Printer.CurrentY = 4200
            Printer.CurrentX = 5200
            Printer.Print(TextBox3.Text)

            Printer.CurrentY = 4200
            Printer.CurrentX = 10600
            Printer.Print(TextBox6.Text)

            Printer.EndDoc()

            'MICROSOFT HELP ''''''''''''''''

            'Create new PrintDocument
            Dim pd As New System.Drawing.Printing.PrintDocument()
            ' Add the event handler, and then print
            AddHandler pd.PrintPage, AddressOf pd_PrintPage
            Printer.Orientation = 2
            ' Print the document
            pd.Print()

            ''''''''''''
        End If

    End Sub

    Private Sub pd_PrintPage(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
        ' MICROSOFT HELP.PART ii '''''''''''
        Dim printFont As New System.Drawing.Font("Arial", 10)

        Dim myRec As New System.Drawing.Rectangle(300, 600, 300, 300)

        Chart1.Printing.PrintPaint(ev.Graphics, myRec)
        '''''''''''''
    End Sub

I really thank your help

Nelson

Viewing all articles
Browse latest Browse all 27333

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>