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 9137369
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:05:42+00:00 2026-06-17T09:05:42+00:00

Possible Duplicate: How to prevent richTextBox to paste images within it? If you’re using

  • 0

Possible Duplicate:
How to prevent richTextBox to paste images within it?

If you’re using Richtextbox, there are several advantages in Richtextbox for example:

we can use color font on it

Setting custom font in a region

Attach files on it.. etc

take a look at the picture:
enter image description here

Here is my problem:

Can i just make it text only?

In my project, attach file or the like is unnecessary at all. I even didn’t want attach or paste an images on it, i just want “text only” on Richtextbox

How can i do that?

  • 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-06-17T09:05:43+00:00Added an answer on June 17, 2026 at 9:05 am

    Since RichTextBox doesn’t have a Images or Objects collection you have to go for the RTF formatting codes. All data of RichTextBox is stored as plain text with special formatting codes, this is exposed by the control through its RTF property. Learning this code language is essential if you want to read or change it, learning resources are easily available throughout the web, see for example this overview. RichTextBox uses more simplified rtf codes than several full-feature editors like MS Word etc, so it is usually beneficial to load data into a RTB before manipulating it, this will remove much redundant data.

    Making a long story short, I found that it is necessary to search for rtf groups that start with either “pict” or “object” command. Knowing that groups may be nested you can’t just find the first end-group char from there, you have to parse the string char by char while keeping count of grouping to find the end of those groups. Now you have enough information to remove that part of the string. Rtf may contain multiple picture/object groups so you have to do this until all are removed. Here is a sample function that return rtf string after removing those groups:

    private string removeRtfObjects(string rtf)
    {
        //removing {\pict or {\object groups
        string pattern = "\\{\\\\pict|\\{\\\\object";
        Match m = Regex.Match(rtf, pattern);
        while (m.Success) {
            int count = 1;
            for (int i = m.Index + 2; i <= rtf.Length; i++) {
                //start group
                if (rtf(i) == '{') {
                    count += 1;
                //end group
                } else if (rtf(i) == '}') {
                    count -= 1;
                }
                //found end of pict/object group
                if (count == 0) {
                    rtf = rtf.Remove(m.Index, i - m.Index + 1);
                    break; // TODO: might not be correct. Was : Exit For
                }
            }
            m = Regex.Match(rtf, pattern);
            //go again
        }
        return rtf;
    }
    

    When should this be done? You have already mention Paste, there is also Insert, these can be trapped with the KeyDown event where you get the clipboard info and handle it accordingly. Setting e.Handled=True when you have handled the operation yourself signals that the control should not do any default processing for this key combination. This is also how you block pasting images without destroying the users clipboard. Example:

    private void RichTextBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
    {
        //aware of Paste or Insert
        if (e.Control && e.KeyCode == Keys.V || e.Shift && e.KeyCode == Keys.I) {
            if (Clipboard.ContainsImage || Clipboard.ContainsFileDropList) {
                //some images are transferred as filedrops
                e.Handled = true;
                //stops here
            } else if (Clipboard.ContainsData(DataFormats.Rtf)) {
                RichTextBox rtbox = new RichTextBox();
                //use a temp box to validate/simplify
                rtbox.Rtf = Clipboard.GetData(DataFormats.Rtf);
                this.RichTextBox1.SelectedRtf = this.removeRtfObjects(rtbox.Rtf);
                rtbox.Dispose();
                e.Handled = true;
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Prevent any form of page refresh using jQuery/Javascript how can i prevent
Possible Duplicate: How can I prevent SQL injection in PHP? This is the example
Possible Duplicate: Is there a clean way to prevent windows.h from creating a near
Possible Duplicate: Prevent execution of parent event handler I'm using a nice plug-in (
Possible Duplicate: How to prevent CALayer from implicit animations? I'm using a CAGradientLayer as
Possible Duplicate: Prevent caching of AJAX call I'm using jQuery to read a tiny
Possible Duplicate: Prevent multiple instances of a given app in .NET? How can I
Possible Duplicate: How to encrypt HTML, CSS and JavaScript to prevent theft Is there
Possible Duplicate: Will using LINQ to SQL help prevent SQL injection I'm using LINQ
Possible Duplicate: Is there a way to prevent a class from being derived from

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.