Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7017955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:58:52+00:00 2026-05-27T22:58:52+00:00

When using the Microsoft RichTextBox control it is possible to add new lines like

  • 0

When using the Microsoft RichTextBox control it is possible to add new lines like this…

richtextbox.AppendText(System.Environment.NewLine); // appends \r\n

However, if you now view the generated rtf the \r\n characters are converted to \par not \line

How do I insert a \line control code into the generated RTF?

What does’t work:

Token Replacement

Hacks like inserting a token at the end of the string and then replacing it after the fact, so something like this:

string text = "my text";
text = text.Replace("||" "|"); // replace any '|' chars with a double '||' so they aren't confused in the output.
text = text.Replace("\r\n", "_|0|_"); // replace \r\n with a placeholder of |0|

richtextbox.AppendText(text);

string rtf = richtextbox.Rtf;
rtf.Replace("_|0|_", "\\line"); // replace placeholder with \line
rtf.Replace("||", "|"); // set back any || chars to |

This almost worked, it breaks down if you have to support right to left text as the right to left control sequence always ends up in the middle of the placeholder.

Sending Key Messages

public void AppendNewLine()
{
    Keys[] keys = new Keys[] {Keys.Shift, Keys.Return};
    SendKeys(keys);
}

private void SendKeys(Keys[] keys)
{
    foreach(Keys key in keys)
    {
        SendKeyDown(key);
    }
}

private void SendKeyDown(Keys key)
{
    user32.SendMessage(this.Handle, Messages.WM_KEYDOWN, (int)key, 0);
}

private void SendKeyUp(Keys key)
{
    user32.SendMessage(this.Handle, Messages.WM_KEYUP, (int)key, 0);
}

This also ends up being converted to a \par

Is there a way to post a messaged directly to the msftedit control to insert a control character?

I am totally stumped, any ideas guys? Thanks for your help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:58:53+00:00Added an answer on May 27, 2026 at 10:58 pm

    Adding a Unicode “Line Separator” (U+2028) does work as far as my testing showed:

    private void Form_Load(object sender, EventArgs e)
    {
        richText.AppendText("Hello, World!\u2028");
        richText.AppendText("Hello, World!\u2028");
        string rtf = richText.Rtf;
        richText.AppendText(rtf);
    }
    

    When I run the program, I get:

    Hello, World!
    Hello, World!
    {\rtf1\ansi\ansicpg1252\deff0\deflang1031{\fonttbl{\f0\fnil\fcharset0 Courier New;}}
    {\colortbl ;\red255\green255\blue255;}
    \viewkind4\uc1\pard\cf1\f0\fs17 Hello, World!\line Hello, World!\line\par
    }
    

    It did add \line instead of \par.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using Microsoft's Charting control, is it possible to add a range of points at
Using Microsoft's charting control, System.Windows.Forms.DataVisualization.Charting.Chart, I am trying to render a chart to vector
Using Microsoft SQL 2000, I will like to join multiples tables (A, B, C,
using System; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; namespace proj { public class game
I'm using a RichTextBox control in a Windows Service to convert RTF to plain
I'm using Microsoft.Web.Administration to create new websites on IIS 7.5 Using mgr As New
Using Microsoft Visual C# I am making a Custom Control that has a list
While using: using Microsoft.VisualStudio.TestTools.UnitTesting It's giving me an reference error under .VisualStudio. Is this
Using Microsoft SQL Server's database mirroring capability, can the mirroring occur between two clusters?
When using Microsoft office automation I want to insert images into a spreadsheet. How

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.