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

  • SEARCH
  • Home
  • 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 496283
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:40:17+00:00 2026-05-13T05:40:17+00:00

For the first time ever, I’m investigating RichTextBox controls in C# Windows forms. I

  • 0

For the first time ever, I’m investigating RichTextBox controls in C# Windows forms. I know I need this control in my app as TextBox is too simple for my needs.

I have the following code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _19_richtextbox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void richTextBoxHome_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == (char)(Keys.Return))
            {
                richTextBoxChat.AppendText("Home:" + richTextBoxHome.Text + "\n");
                richTextBoxHome.Clear();
            }
        }
    }
}

For the moment I just want whatever is typed in one RichTextBox to be displayed on the other RichTextBox on hitting Return.

The issue is that everytime I hit Return, the data is being transfered to the other control but the first control is left with a carriage return before the cursor. This happens everytime I hit Return. Both the controls accept multiline input. How do I make it stop doing this?


i would like a way to make the “Home:” part in bold.

i have found very little info on this on my searches. the following are the only actual code that i could understand.

rtb1.Rtf = @"{\rtf1\ansi {\b hello} {\i World}}" ; 
richTextBox1.Rtf = @"{\rtf1\ansi This is in \b bold\b0.}";

im not sure how to proceed with this info. i just want the richtextbox to display “Home:” and “Away:” in bold and be able to handle URLs in text.

please advise what should i specify when searching this potic on google or any reference your could think of would be of great help.

thank you again for taking interest.


i have made progress on my issue and thought to share.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace _19_richtextbox
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void richTextBoxHome_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (char)(Keys.Enter))
            {
                e.Handled = true;

                // richTextBoxChat.Rtf = @"{\rtf1 \b Home: \bO}" + @richTextBoxHome;

                // do not delete next 2 lines
                //string test = @"{\rtf1 \b Home: \b0";
                //test = test + richTextBoxHome.Rtf + "}";

                string chatBuffer = richTextBoxChat.Rtf;

                string buffer = @"{\rtf1";
                buffer = buffer + chatBuffer;

                buffer = buffer + @"\b Home:\b0";

                buffer = buffer + richTextBoxHome.Rtf + "}";


               // MessageBox.Show(buffer);
                richTextBoxChat.Rtf = buffer;
                //do not delete the following 2 lines
                //richTextBoxChat.AppendText("Home:" + richTextBoxHome.Text);
                richTextBoxHome.Clear();
            }
        }

    }
}

just need to figure out how to get rid of the new lines/carriage returns in the text.

any tips most welcome.

thanks.


that did not workout so well. ended up using the below instead.

            this.richTextBoxChat.SelectionFont = new Font(this.richTextBoxChat.Font.FontFamily, this.Font.Size, FontStyle.Bold);
            richTextBoxChat.AppendText("Home: ");
            this.richTextBoxChat.SelectionFont = new Font(this.richTextBoxChat.Font.FontFamily, this.Font.Size, FontStyle.Regular);
            richTextBoxChat.AppendText(richTextBoxHome.Text);
            richTextBoxChat.ScrollToCaret();
            richTextBoxHome.Clear();
  • 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-13T05:40:17+00:00Added an answer on May 13, 2026 at 5:40 am

    You can set the event to handled to prevent further processing of the return keydown event

    Try this:

        private void richTextBoxHome_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyValue == (char)(Keys.Return))
            {
                richTextBoxChat.AppendText("Home:" + richTextBoxHome.Text + "\n");
                richTextBoxHome.Clear();
    
                e.Handled = true;
                e.SuppressKeyPress = true;
    
            }
        }
    

    Edit: added e.SuppressKeyPress = true; Cory Charlton pointed this out in his post.

    Edit: also, as others have mentioned, use the KeyPress event handler, so if someone holds down enter/return the event is triggered over and over again.
    an example of the usage is as follows:

        private void richTextBoxHome_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar.Equals((Char) Keys.Enter))
            {
                richTextBoxChat.AppendText("Home:" + richTextBoxHome.Text + "\n");
                richTextBoxHome.Clear();
    
                e.Handled = true;
            }
        }
    

    Edit: Also, there is a Property you can set on the RichTextBox to not allow MultiLine strings to be entered into the textbox. This does pose a problem when pasting content with multiple lines, it will only take the first line.

    For Bold words:
    You can change the SelectionFont of the RichTextBox to set it’s font attributes:

        private readonly Font BoldSelectionFont = new Font("Arial", 9.0f, FontStyle.Bold);
        private readonly Font RegSelectionFont = new Font("Arial", 9.0f, FontStyle.Regular);
    
    ...
                    richTextBoxChat.SelectionFont = BoldSelectionFont;
                    richTextBoxChat.AppendText("Home: ");
                    richTextBoxChat.SelectionFont = RegSelectionFont;
                    richTextBoxChat.AppendText(richTextBoxHome.Text + "\n");
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is the first time ever I'm using AJAX, and I want to do
Here's my two scenarios. 1 - User opens app for the first time ever
this is my first time ever posting a question and I am kind of
This was my first time ever trying to save object in a file, so
This is the first time I've ever tried to use JAXB for anything at
This is the first time I've ever tried JQuery basically because I couldnt get
I have recently started learning F#, and this is the first time I've ever
I'm am super new at this, and this is my first time ever using
Somehow this is the first time I've ever encountered this problem in many years
This is my first time ever using sockets, and I am having trouble accepting

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.