نمایش نتایج 1 تا 3 از 3

نام تاپیک: چطوری محتوای RichTextBox رو پرینت کنم؟

  1. #1

    چطوری محتوای RichTextBox رو پرینت کنم؟

    سلام
    یه RTB دارم که محتوای خودش رو از فایلی به نام (مثلاً) MyFile.rtf می گیره. حالا میخوام وقتی کاربر روی دکمه Print کلیک می کنه، بعد از این که PrintDialog ظاهر شد و OK کرد، محتویات اون RTB پرینت بشه. بلدم PrintDialog رو بیارم ولی وقتی OK کرد دیگه نمی دونم چطوری محتویات رو به پرینتر بفرستم.

  2. #2
    ؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟؟

  3. #3
    کاربر دائمی آواتار yavari
    تاریخ عضویت
    مهر 1384
    محل زندگی
    ایران - یزد
    پست
    1,014
    سلام

        ' PrintPage is the foundational printing event. This event gets fired for every 
    ' page that will be printed. You could also handle the BeginPrint and EndPrint
    ' events for more control.
    '
    ' The following is very
    ' fast and useful for plain text as MeasureString calculates the text that
    ' can be fitted on an entire page. This is not that useful, however, for
    ' formatted text. In that case you would want to have word-level (vs page-level)
    ' control, which is more complicated.
    Private Sub pdoc_PrintPage(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles pdoc.PrintPage
    ' Declare a variable to hold the position of the last printed char. Declare
    ' as static so that subsequent PrintPage events can reference it.
    Static intCurrentChar As Int32
    ' Initialize the font to be used for printing.
    Dim font As New Font("Tahoma", 14)
    Dim intPrintAreaHeight, intPrintAreaWidth, marginLeft, marginTop As Int32
    With pdoc.DefaultPageSettings
    ' Initialize local variables that contain the bounds of the printing
    ' area rectangle.
    intPrintAreaHeight = .PaperSize.Height - .Margins.Top - .Margins.Bottom
    intPrintAreaWidth = .PaperSize.Width - .Margins.Left - .Margins.Right
    ' Initialize 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 ' X coordinate
    marginTop = .Margins.Top ' Y coordinate
    End With
    ' If the user selected Landscape mode, swap the printing area height
    ' and width.
    If pdoc.DefaultPageSettings.Landscape Then
    Dim intTemp As Int32
    intTemp = intPrintAreaHeight
    intPrintAreaHeight = intPrintAreaWidth
    intPrintAreaWidth = intTemp
    End If
    ' Calculate the total number of lines in the document based on the height of
    ' the printing area and the height of the font.
    Dim intLineCount As Int32 = CInt(intPrintAreaHeight / font.Height)
    ' Initialize the rectangle structure that defines the printing area.
    Dim rectPrintingArea As New RectangleF(marginLeft, marginTop, intPrintAreaWidth, intPrintAreaHeight)
    ' Instantiate the StringFormat class, which encapsulates text layout
    ' information (such as alignment and line spacing), display manipulations
    ' (such as ellipsis insertion and national digit substitution) and OpenType
    ' features. Use of StringFormat causes MeasureString and DrawString to use
    ' only an integer number of lines when printing each page, ignoring partial
    ' lines that would otherwise likely be printed if the number of lines per
    ' page do not divide up cleanly for each page (which is usually the case).
    ' See further discussion in the SDK documentation about StringFormatFlags.
    Dim fmt As New StringFormat(StringFormatFlags.LineLimit)
    ' Call MeasureString to determine the number of characters that will fit in
    ' the printing area rectangle. The CharFitted Int32 is passed ByRef and used
    ' later when calculating intCurrentChar and thus HasMorePages. LinesFilled
    ' is not needed for this sample but must be passed when passing CharsFitted.
    ' Mid is used to pass the segment of remaining text left off from the
    ' previous page of printing (recall that intCurrentChar was declared as
    ' static.
    Dim intLinesFilled, intCharsFitted As Int32
    e.Graphics.MeasureString(Mid(RichTextBoxHS1.Text, intCurrentChar + 1), font, _
    New SizeF(intPrintAreaWidth, intPrintAreaHeight), fmt, _
    intCharsFitted, intLinesFilled)
    ' Print the text to the page.
    e.Graphics.DrawString(Mid(RichTextBoxHS1.Text, intCurrentChar + 1), font, _
    Brushes.Black, rectPrintingArea, fmt)
    ' Advance the current char to the last char printed on this page. As
    ' intCurrentChar is a static variable, its value can be used for the next
    ' page to be printed. It is advanced by 1 and passed to Mid() to print the
    ' next page (see above in MeasureString()).
    intCurrentChar += intCharsFitted
    ' HasMorePages tells the printing module whether another PrintPage event
    ' should be fired.
    If intCurrentChar < Me.RichTextBoxHS1.Text.Length Then
    e.HasMorePages = True
    Else
    e.HasMorePages = False
    ' You must explicitly reset intCurrentChar as it is static.
    intCurrentChar = 0
    End If
    End Sub


        Private Sub btnpageSetup_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpageSetup.Click
    On Error Resume Next
    Dim psd As New PageSetupDialog
    With psd
    .Document = pdoc
    .PageSettings = pdoc.DefaultPageSettings
    End With
    If psd.ShowDialog = DialogResult.OK Then
    pdoc.DefaultPageSettings = psd.PageSettings
    End If
    End Sub


    امیدوارم به دردتون بخوره !
    موفق باشید

تاپیک های مشابه

  1. چگونگی ذخیره richTextBox در پایگاه داده
    نوشته شده توسط M * M * A در بخش C#‎‎
    پاسخ: 6
    آخرین پست: چهارشنبه 27 تیر 1386, 14:20 عصر
  2. richtextbox
    نوشته شده توسط shahrzad2 در بخش C#‎‎
    پاسخ: 1
    آخرین پست: پنج شنبه 24 خرداد 1386, 23:44 عصر
  3. پرینت متن فارسی درون RichTextBox کنترل
    نوشته شده توسط hamid_isf_1360 در بخش C#‎‎
    پاسخ: 10
    آخرین پست: جمعه 11 خرداد 1386, 23:55 عصر
  4. گذاشتن جدول در richtextbox
    نوشته شده توسط mina_at2000 در بخش VB.NET
    پاسخ: 1
    آخرین پست: جمعه 17 آذر 1385, 23:08 عصر

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •