Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. protect RTF

protect RTF

Scheduled Pinned Locked Moved C#
question
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    likefood
    wrote on last edited by
    #1

    I just discovered the "\protect" and "\protect0" RTF code word (whatever RTF people call them, code words or tags or whatever). I wanted to implement it into my little program (it has a RichTextBox control). I can get it to protect the rich text just fine (cannot be edited), but it's not unprotecting protected text at all. Can someone please take a look at my code snippet and tell me what I'm doing wrong? Note: The following code is inside my KeyDown event handler, inside an if-block that checks for the CTRL key being down, so CTRL+P makes this run. if (e.KeyCode == Keys.P)//protection, not printing {      string line = rtf.SelectedRtf;      string text = rtf.SelectedText;      Console.WriteLine("-----LINE-----\r\n{0}\r\n", line);      if (line.IndexOf("\\protect") > -1)//has protection therein      {           Console.WriteLine("unprotected:");           line = line.Replace("\\protect0", "");           line = line.Replace("\\protect", "");           Console.WriteLine(line);           rtf.SelectedRtf = line;      }      else      {           Console.WriteLine("protected");           int start = line.IndexOf(text, line.LastIndexOf("\\"));           int end = start + text.Length;           line = line.Insert(end, @"\protect0");           line = line.Insert(start - 1, @"\protect");           rtf.SelectedRtf = line;      } }

    -Daniel Typing too fast fro my owngood

    S 1 Reply Last reply
    0
    • L likefood

      I just discovered the "\protect" and "\protect0" RTF code word (whatever RTF people call them, code words or tags or whatever). I wanted to implement it into my little program (it has a RichTextBox control). I can get it to protect the rich text just fine (cannot be edited), but it's not unprotecting protected text at all. Can someone please take a look at my code snippet and tell me what I'm doing wrong? Note: The following code is inside my KeyDown event handler, inside an if-block that checks for the CTRL key being down, so CTRL+P makes this run. if (e.KeyCode == Keys.P)//protection, not printing {      string line = rtf.SelectedRtf;      string text = rtf.SelectedText;      Console.WriteLine("-----LINE-----\r\n{0}\r\n", line);      if (line.IndexOf("\\protect") > -1)//has protection therein      {           Console.WriteLine("unprotected:");           line = line.Replace("\\protect0", "");           line = line.Replace("\\protect", "");           Console.WriteLine(line);           rtf.SelectedRtf = line;      }      else      {           Console.WriteLine("protected");           int start = line.IndexOf(text, line.LastIndexOf("\\"));           int end = start + text.Length;           line = line.Insert(end, @"\protect0");           line = line.Insert(start - 1, @"\protect");           rtf.SelectedRtf = line;      } }

      -Daniel Typing too fast fro my owngood

      S Offline
      S Offline
      ShishirVaidya
      wrote on last edited by
      #2

      This is just to help new people. In this code following line of code should be changed string line = rtf.SelectedRtf; string text = rtf.SelectedText; TO string line = rtf.Rtf; string text = rtf.Text; It works for me after making this change Thanks

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups