VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,469 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,736 people online right now. Registration is fast and FREE... Join Now!




how to print content of rich text box

 

how to print content of rich text box, please help me ..............................

mrvijayks

1 Oct, 2008 - 11:20 PM
Post #1

New D.I.C Head
*

Joined: 1 Oct, 2008
Posts: 1

i m using a richtextbox to show the result of query, which is working
i m getting the rows from table

now i have a print button on the same form i would like to print the content of richtext box when user click on print button

CODE
Imports System.Data.OleDb
Public Class Form7
    Dim cn As OleDbConnection
    Dim cmd As OleDbCommand
    Dim dr As OleDbDataReader
    Dim mname, madd, mmob, mid, str1, str2 As String
    Dim da As Date
    Dim ti As Date
    Dim id, am_pm, date1, date2 As String
    Dim milk_lit, fat_per, fat_kg, rate, fat_amt As Double
    Dim i, j, k As Integer

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Hide()
        Form3.Show()

    End Sub

    Private Sub Form7_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        Try
            cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\db1.mdb;Jet OLEDB:Database Password=vijay")
            'provider to be used when working with access database
            cn.Open()
            cmd = New OleDbCommand("select milkmanid,milk_man_name,address,mobno from table2", cn)
            dr = cmd.ExecuteReader
            While dr.Read()
                ComboBox1.Items.Add(dr(0) & ", " & dr(1) & ", " & dr(2) & ", " & dr(3))
                ' loading data into combobox1 by column index
            End While
        Catch v1 As Exception
            MsgBox(v1, MsgBoxStyle.Information)
        End Try
        cn.Close()




    End Sub

  
    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Me.Close()
        Form3.Show()
    End Sub

    Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click
        
'what code i write here to print the content of richtextbox1
      dim content as string
      content=richtextbox1.text
    End Sub

    Private Sub ReportViewer1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        mname = ComboBox1.SelectedItem
        date1 = DateTimePicker1.Value.Date
        date2 = DateTimePicker2.Value.Date
        mid = mname.Substring(0, mname.IndexOf(","))

        RichTextBox1.Text = "Milk Purchaser report" & ControlChars.CrLf
        RichTextBox1.AppendText("Client name  :" & mname & ControlChars.CrLf)
        RichTextBox1.AppendText("From  " & date1 & " to " & date2 & ControlChars.CrLf)
        RichTextBox1.AppendText(ControlChars.CrLf)
        RichTextBox1.AppendText(ControlChars.CrLf)
        RichTextBox1.AppendText("-----------------------------------------------------------------------------------------")
        RichTextBox1.AppendText(ControlChars.CrLf)

        RichTextBox1.AppendText("date          am_pm        milk lit       fat %       fat kg       rate      fat Amt" & ControlChars.CrLf)
        RichTextBox1.AppendText("-----------------------------------------------------------------------------------------")
        RichTextBox1.AppendText(ControlChars.CrLf)
        Dim t_fat_kg, tamt As Integer
        t_fat_kg = 0
        tamt = 0
        Try
            cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\db1.mdb;Jet OLEDB:Database Password=vijay")
            'provider to be used when working with access database
            cn.Open()
            k = mid
            str1 = "select milk_man_name from table2 where milkmanid=" & k & ""
            str2 = "SELECT milkmanid, mdate, am_pm, milk_lit, fat_per, fat_kg, rate, fat_amt FROM milk_entry WHERE (((milkmanid)=" & k & ") AND ((mdate) Between #" & date1 & "# And #" & date2 & "#));"

            cmd = New OleDbCommand(str1, cn)
            dr = cmd.ExecuteReader
            While dr.Read()
                mname = dr(0)
            End While
            cmd = New OleDbCommand(str2, cn)
            dr = cmd.ExecuteReader
            While dr.Read()
                id = dr(0)
                date1 = dr(1)
                am_pm = dr(2)
                milk_lit = dr.GetDouble(3)
                fat_per = dr.GetDouble(4)
                fat_kg = dr.GetDouble(5)
                rate = dr.GetDouble(6)
                fat_amt = dr.GetDouble(7)
                
                RichTextBox1.AppendText(date1 & "   " & am_pm & "             " & CDbl(milk_lit) & "           " & CDbl(fat_per) & "           " & fat_kg & "           " & rate & "         " & fat_amt & ControlChars.CrLf)
                t_fat_kg = t_fat_kg + fat_kg
                tamt = tamt + fat_amt
            End While
            RichTextBox1.AppendText(ControlChars.CrLf)
            RichTextBox1.AppendText("-----------------------------------------------------------------------------------------" & ControlChars.CrLf)
            RichTextBox1.AppendText("                                                                      " & t_fat_kg & "                  total : " & tamt)


        Catch v1 As Exception
            MsgBox(v1, MsgBoxStyle.Information)
        End Try
        cn.Close()
    End Sub
End Class



This post has been edited by mrvijayks: 2 Oct, 2008 - 10:03 PM

User is offlineProfile CardPM
+Quote Post


Jayman

RE: How To Print Content Of Rich Text Box

2 Oct, 2008 - 10:04 AM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 8,544



Thanked: 226 times
Dream Kudos: 500
Expert In: Everything

My Contributions
What have you tried so far?

Post your code and we will help you get it working.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 02:41AM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month