Print the RichTextBox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • James Wong

    Print the RichTextBox

    Hi,

    I use the RichTextBox in my program.
    It will use different language in this RichTextBox (chinese and english
    characters), and it set the "DualFont" and use different fonts.
    By the way, how can I print out this content to printer easily?

    Thanks!

    James


  • James Wong

    #2
    Re: Print the RichTextBox

    PS. Print the content with the same format of RichTextBox.


    "James Wong" <cphk_msdn@nosp am.nospam¼¶¼g©ó ¶l¥ó·s»D:OhieDh w1GHA.4300@TK2M SFTNGP03.phx.gb l...
    Hi,
    >
    I use the RichTextBox in my program.
    It will use different language in this RichTextBox (chinese and english
    characters), and it set the "DualFont" and use different fonts.
    By the way, how can I print out this content to printer easily?
    >
    Thanks!
    >
    James
    >

    Comment

    • Herfried K. Wagner [MVP]

      #3
      Re: Print the RichTextBox

      "James Wong" <cphk_msdn@nosp am.nospamschrie b:
      I use the RichTextBox in my program.
      By the way, how can I print out this content to printer easily?
      HOW TO: Print the Content of a RichTextBox by Using Microsoft Visual Basic
      ..NET
      <URL:http://support.microso ft.com/?scid=kb;EN-US;811401>

      Getting WYSIWYG Print Results from a .NET RichTextBox
      <URL:http://msdn.microsoft. com/library/en-us/dnwinforms/html/wnf_RichTextBox .asp>

      --
      M S Herfried K. Wagner
      M V P <URL:http://dotnet.mvps.org/>
      V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

      Comment

      • James Wong

        #4
        Re: Print the RichTextBox

        Hi,

        I solve this problem.
        thank you for your solution~

        James


        "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at>
        ???????:OGqsPZ0 1GHA.1300@TK2MS FTNGP05.phx.gbl ...
        "James Wong" <cphk_msdn@nosp am.nospamschrie b:
        >I use the RichTextBox in my program.
        >By the way, how can I print out this content to printer easily?
        >
        HOW TO: Print the Content of a RichTextBox by Using Microsoft Visual Basic
        .NET
        <URL:http://support.microso ft.com/?scid=kb;EN-US;811401>
        >
        Getting WYSIWYG Print Results from a .NET RichTextBox
        <URL:http://msdn.microsoft. com/library/en-us/dnwinforms/html/wnf_RichTextBox .asp>
        >
        --
        M S Herfried K. Wagner
        M V P <URL:http://dotnet.mvps.org/>
        V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

        Comment

        • James Wong

          #5
          Re: Print the RichTextBox

          Hi,

          I have another questions for the RichTextBox.

          1) How can i get the height & width of content in this RichTextBox with font
          format?
          2) Can I set the position layout of RichTextBox in paper?

          Thanks!

          James

          "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at>
          ???????:OGqsPZ0 1GHA.1300@TK2MS FTNGP05.phx.gbl ...
          "James Wong" <cphk_msdn@nosp am.nospamschrie b:
          >I use the RichTextBox in my program.
          >By the way, how can I print out this content to printer easily?
          >
          HOW TO: Print the Content of a RichTextBox by Using Microsoft Visual Basic
          .NET
          <URL:http://support.microso ft.com/?scid=kb;EN-US;811401>
          >
          Getting WYSIWYG Print Results from a .NET RichTextBox
          <URL:http://msdn.microsoft. com/library/en-us/dnwinforms/html/wnf_RichTextBox .asp>
          >
          --
          M S Herfried K. Wagner
          M V P <URL:http://dotnet.mvps.org/>
          V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

          Comment

          • Linda Liu [MSFT]

            #6
            Re: Print the RichTextBox

            Hi James,
            >1) How can i get the height & width of content in this RichTextBox with
            font format?

            RichTextBox has a ContentsResized event, which will bring us the new
            requested size in its event args. Is it what you need?
            >2) Can I set the position layout of RichTextBox in paper?
            I'm sorry that I couldn't understand what you mean. Could you please
            explain more?

            I look forward to your reply.


            Sincerely,
            Linda Liu
            Microsoft Online Community Support

            =============== =============== =============== =====
            Get notification to my posts through email? Please refer to
            Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

            ications.

            Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
            where an initial response from the community or a Microsoft Support
            Engineer within 1 business day is acceptable. Please note that each follow
            up response may take approximately 2 business days as the support
            professional working with you may need further investigation to reach the
            most efficient resolution. The offering is not appropriate for situations
            that require urgent, real-time or phone-based interactions or complex
            project analysis and dump analysis issues. Issues of this nature are best
            handled working with a dedicated Microsoft Support Engineer by contacting
            Microsoft Customer Support Services (CSS) at
            http://msdn.microsoft.com/subscripti...t/default.aspx.
            =============== =============== =============== =====

            This posting is provided "AS IS" with no warranties, and confers no rights.

            Comment

            • James Wong

              #7
              Re: Print the RichTextBox

              Hi Linda,

              I use the DualFont function in RichTextBox, but it seems not work.

              example 1:
              RichTextBoxPrin tCtrl1.Language Option = RichTextBoxLang uageOptions.Dua lFont
              RichTextBoxPrin tCtrl1.Text = "{some chinese characters} ABCDEF"
              RichTextBoxPrin tCtrl1.Font = New Font("{chinese font}", 12)
              RichTextBoxPrin tCtrl1.Font = New Font("Gill Sans Ultra Bold", 40)

              It occurs two fonts ("{chinese font}" & "Gill Sans Ultra Bold"), but the
              font size is 40.
              -----------------------------------------------------------------------------------------------------------

              example 2:
              RichTextBoxPrin tCtrl1.Language Option = RichTextBoxLang uageOptions.Dua lFont
              RichTextBoxPrin tCtrl1.Text = "{some chinese characters} ABCDEF"
              RichTextBoxPrin tCtrl1.Font = New Font("Gill Sans Ultra Bold", 40)
              RichTextBoxPrin tCtrl1.Font = New Font("{chinese font}", 12)

              It occurs one font only ("{chinese font}"), but the font size is 12.
              -----------------------------------------------------------------------------------------------------------

              Furthermore, I read this article. (
              http://support.microsoft.com/?scid=kb;EN-US;811401 )
              If my project has many RichTextBox, can I print these contents in one paper?

              By the way, how can I set the coordinates of print out paper using
              RichTextBox?
              e.g. adjust to center, adjust 2 cm in left side...

              Thanks~

              James


              "Linda Liu [MSFT]" <v-lliu@online.mic rosoft.com¼¶¼g© ó¶l¥ó·s»D:P4GG1 i$1GHA.4464@TK2 MSFTNGXA01.phx. gbl...
              Hi James,
              >
              >>1) How can i get the height & width of content in this RichTextBox with
              font format?
              >
              RichTextBox has a ContentsResized event, which will bring us the new
              requested size in its event args. Is it what you need?
              >
              >>2) Can I set the position layout of RichTextBox in paper?
              >
              I'm sorry that I couldn't understand what you mean. Could you please
              explain more?
              >
              I look forward to your reply.
              >
              >
              Sincerely,
              Linda Liu
              Microsoft Online Community Support
              >
              =============== =============== =============== =====
              Get notification to my posts through email? Please refer to
              Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

              ications.
              >
              Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
              where an initial response from the community or a Microsoft Support
              Engineer within 1 business day is acceptable. Please note that each follow
              up response may take approximately 2 business days as the support
              professional working with you may need further investigation to reach the
              most efficient resolution. The offering is not appropriate for situations
              that require urgent, real-time or phone-based interactions or complex
              project analysis and dump analysis issues. Issues of this nature are best
              handled working with a dedicated Microsoft Support Engineer by contacting
              Microsoft Customer Support Services (CSS) at
              http://msdn.microsoft.com/subscripti...t/default.aspx.
              =============== =============== =============== =====
              >
              This posting is provided "AS IS" with no warranties, and confers no
              rights.
              >

              Comment

              • Linda Liu [MSFT]

                #8
                Re: Print the RichTextBox

                Hi James,

                This is a quick note to let you know that I am researching on this issue
                and will get it back to you ASAP.

                I appreciate your patience.


                Sincerely,
                Linda Liu
                Microsoft Online Community Support


                Comment

                • Linda Liu [MSFT]

                  #9
                  Re: Print the RichTextBox

                  Hi James,

                  Sorry for my delayed reply.

                  The LanguageOption property of RichTextBox is new in .NET 2.0. This
                  property gets or sets a value that indicates RichTextBox settings for Input
                  Method Editor (IME) and Asian language support. The default value of the
                  LanguageOption property of RichTextBox is AutoFont|DualFo nt. That's to say,
                  RichTextBox supports DualFont by default.

                  When a richtextbox supports DualFont, it doesn't means that we could set an
                  English font for ASCII text and an Asian font for Asian text at one time.
                  Instead, we should make use of the SelectionFont property of the
                  richtextbox to set fonts for the two kinds of text respectively.

                  For example, we could add two buttons called button1 and button2 on the
                  form. Click button1 to set an English font for ASCII text and click button2
                  to set an Asian font for Asian text. To set the ASCII text in the
                  richtextbox to the English font, select the ASCII text in the richtextbox
                  and click button1. To set the Asian text in the richtextbox to the Asian
                  font, select the Asian text in the richtextbox and click button2.
                  If my project has many RichTextBox, can I print these contents in one
                  paper?

                  In the sample provided in the Microsoft support website, the actual
                  printing work is done by the SendMessage Win32 API, which is called in the
                  Print method in the RichTextBoxPrin tCtrl class. This line of code is 'res =
                  SendMessage(Han dle, EM_FORMATRANGE, wparam, lparam);'. Note that the
                  richtextboxctrl control's Handle is passed to the SendMessage function.
                  This means that we could only print out the content in ONE richtextboxctrl
                  control at one time.

                  To print out the contents in several richtextboxctrl s at one time in one
                  paper, we could copy the contents in all the richtextboxctrl s into one
                  richtextboxctrl and print the total content out and restore the content in
                  the richtextboxctrl after the printing is finished. Suppose there're two
                  richtextboxctrl s on the form. The following is a sample to print out
                  contents in both richtextboxctrl s at one time.

                  void printDocument1_ BeginPrint(obje ct sender,
                  System.Drawing. Printing.PrintE ventArgs e)
                  {
                  this.richTextBo xPrintCtrl2.Sel ectAll();
                  this.richTextBo xPrintCtrl2.Cop y();

                  this.richTextBo xPrintCtrl1.Foc us();
                  this.richTextBo xPrintCtrl1.Sel ectionStart =
                  this.richTextBo xPrintCtrl2.Tex tLength;
                  this.richTextBo xPrintCtrl1.Pas te();

                  checkPrint = 0;
                  }

                  void printDocument1_ EndPrint(object sender,
                  System.Drawing. Printing.PrintE ventArgs e)
                  {
                  this.richTextBo xPrintCtrl1.Und o();
                  }
                  how can I set the coordinates of print out paper using RichTextBox? e.g.
                  adjust to center, adjust 2 cm in left side...

                  You could make use of the DefaultPageSett ings property of PrintDocument to
                  set the page margin. The following is a sample.

                  this.printDocum ent1.DefaultPag eSettings.Margi ns.Left = 200;

                  Hope this helps.
                  If you have anything unclear, please feel free to let me know.


                  Sincerely,
                  Linda Liu
                  Microsoft Online Community Support


                  Comment

                  • James Wong

                    #10
                    Re: Print the RichTextBox

                    Hi Linda,

                    thanks for the reply

                    James



                    "Linda Liu [MSFT]" <v-lliu@online.mic rosoft.com¼¶¼g© ó¶l¥ó·s»D:39eoK s82GHA.4464@TK2 MSFTNGXA01.phx. gbl...
                    Hi James,
                    >
                    Sorry for my delayed reply.
                    >
                    The LanguageOption property of RichTextBox is new in .NET 2.0. This
                    property gets or sets a value that indicates RichTextBox settings for
                    Input
                    Method Editor (IME) and Asian language support. The default value of the
                    LanguageOption property of RichTextBox is AutoFont|DualFo nt. That's to
                    say,
                    RichTextBox supports DualFont by default.
                    >
                    When a richtextbox supports DualFont, it doesn't means that we could set
                    an
                    English font for ASCII text and an Asian font for Asian text at one time.
                    Instead, we should make use of the SelectionFont property of the
                    richtextbox to set fonts for the two kinds of text respectively.
                    >
                    For example, we could add two buttons called button1 and button2 on the
                    form. Click button1 to set an English font for ASCII text and click
                    button2
                    to set an Asian font for Asian text. To set the ASCII text in the
                    richtextbox to the English font, select the ASCII text in the richtextbox
                    and click button1. To set the Asian text in the richtextbox to the Asian
                    font, select the Asian text in the richtextbox and click button2.
                    >
                    >If my project has many RichTextBox, can I print these contents in one
                    paper?
                    >
                    In the sample provided in the Microsoft support website, the actual
                    printing work is done by the SendMessage Win32 API, which is called in the
                    Print method in the RichTextBoxPrin tCtrl class. This line of code is 'res
                    =
                    SendMessage(Han dle, EM_FORMATRANGE, wparam, lparam);'. Note that the
                    richtextboxctrl control's Handle is passed to the SendMessage function.
                    This means that we could only print out the content in ONE richtextboxctrl
                    control at one time.
                    >
                    To print out the contents in several richtextboxctrl s at one time in one
                    paper, we could copy the contents in all the richtextboxctrl s into one
                    richtextboxctrl and print the total content out and restore the content in
                    the richtextboxctrl after the printing is finished. Suppose there're two
                    richtextboxctrl s on the form. The following is a sample to print out
                    contents in both richtextboxctrl s at one time.
                    >
                    void printDocument1_ BeginPrint(obje ct sender,
                    System.Drawing. Printing.PrintE ventArgs e)
                    {
                    this.richTextBo xPrintCtrl2.Sel ectAll();
                    this.richTextBo xPrintCtrl2.Cop y();
                    >
                    this.richTextBo xPrintCtrl1.Foc us();
                    this.richTextBo xPrintCtrl1.Sel ectionStart =
                    this.richTextBo xPrintCtrl2.Tex tLength;
                    this.richTextBo xPrintCtrl1.Pas te();
                    >
                    checkPrint = 0;
                    }
                    >
                    void printDocument1_ EndPrint(object sender,
                    System.Drawing. Printing.PrintE ventArgs e)
                    {
                    this.richTextBo xPrintCtrl1.Und o();
                    }
                    >
                    >how can I set the coordinates of print out paper using RichTextBox? e.g.
                    adjust to center, adjust 2 cm in left side...
                    >
                    You could make use of the DefaultPageSett ings property of PrintDocument to
                    set the page margin. The following is a sample.
                    >
                    this.printDocum ent1.DefaultPag eSettings.Margi ns.Left = 200;
                    >
                    Hope this helps.
                    If you have anything unclear, please feel free to let me know.
                    >
                    >
                    Sincerely,
                    Linda Liu
                    Microsoft Online Community Support
                    >
                    >

                    Comment

                    Working...