469,364 Members | 2,398 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,364 developers. It's quick & easy.

create bold,Italic Paragraph Tag...in Richtextbox

here i created sequence no. with every paragraph line

..

like...

<p local_id = P-100>aaaaaaaaaaaaaaaaaaaaaaaaa<\p>
<p local_id = P-101>bbbbbbbbbbbbbbbbbbbbbbbbb<\p>
<p local_id = P-102>vvvvvvvvvvvvvvvv<\p>



and show in richtextbox control..

here is my code:-

Expand|Select|Wrap|Line Numbers
  1. private void button1_Click(object sender, EventArgs e)
  2.         {
  3.             try
  4.             {
  5.                 OpenFileDialog ofd = new OpenFileDialog();
  6.                 //Font fonttext = null;
  7.  
  8.                 ofd.DefaultExt = "*rtf";
  9.                 ofd.Filter = "RTF File|*.rtf";
  10.                 ofd.ShowDialog();
  11.                 textBox1.Text = ofd.FileName.ToString();
  12.                 filepath = ofd.FileName.ToString();
  13.  
  14.                 //FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);
  15.                 //StreamReader sr = new StreamReader(fs);
  16.  
  17.                 richTextBox1.LoadFile(filepath,RichTextBoxStreamType.RichText);
  18.                 string inputstring = richTextBox1.Text;
  19.                 StringBuilder sb = new StringBuilder(inputstring);
  20.                 //Font fonttext = new Font(sb);
  21.  
  22.                 //if (fonttext.Bold)
  23.                 //sb.Append(@"<B>");
  24.  
  25.                 //string xx = inputstring;
  26.                 //string yy = xx.Replace("", "");
  27.                 ////if (fonttext.Bold)
  28.                 ////    sb.Insert(0, "<B>");
  29.                 ////else if
  30.                 ////    (fonttext.Italic)
  31.                 ////    sb.Insert(0, "<I>");
  32.                 ////else
  33.  
  34.                 sb.Insert(0, "<p>");
  35.                 //string yy = xx.Replace("", "");
  36.                 //sb.Replace("<p>", "");
  37.                 //int num = 0;
  38.                 // sb.Replace("<p>"
  39.  
  40.                 sb.Replace("\n", "</p>" + "\n" + "<p>");
  41.                 sb.Replace("<p>" + "</p>", "");
  42.                 sb.Append("</p>");
  43.                 sb.Replace("<p>" + "</p>", "");
  44.                 sb.Replace("\n\n", "\n");
  45.                 sb.Replace("\n\n", "\n");
  46.                 sb.Replace("\n\n", "\n");
  47.                 sb.Replace("\n\n", "\n");
  48.                 sb.Replace("\n\n", "\n");
  49.                 sb.Replace("\n\n", "\n");
  50.                 int p=0;
  51.                 string xx = sb.ToString ();
  52.                 int ppara = 0;
  53.                 ppara = xx.IndexOf("<p>", 0);
  54.                 while (ppara!=  -1)
  55.                 {
  56.                     p = p+1;
  57.                     ////string f1 = Convert.ToString(p);
  58.                     //f1.ToString().PadLeft(8);
  59.                     xx = xx.Remove(ppara, 3);
  60.                     //if (fonttext.Bold)
  61.                     //    xx = xx.Insert(ppara, "<p local-id=\"B-" + p + "\">");
  62.                     //else
  63.                         xx = xx.Insert(ppara, "<p local-id=\"p-" + p + "\">");
  64.                     ppara = xx.IndexOf("<p>", ppara+3);
  65.                 }
  66.  
  67.                 richTextBox1.Text = xx.ToString();
  68.  
  69.             }
  70.            //}
  71.             catch (Exception ex)
  72.             {
  73.                 MessageBox.Show(ex.Message);
  74.             }
  75.         }

problem is that, if there is any bold,italic paragraph.then he show output in richtextbox like...
<p local-id=\"p-" + p + "\">">wwwwwwwwwwwwww<\p>
<B local-id=\"B-" + p + "\">">aaaaaaaaaaaaa<\B>
<I local-id=\"I-" + p + "\">">yyyyyyyyyyyyyy<\I>

then how??
Nov 8 '08 #1
0 2682

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

2 posts views Thread by Imaya Kumar | last post: by
6 posts views Thread by Ronny sigo | last post: by
2 posts views Thread by Adam Honek | last post: by
4 posts views Thread by paraidy | last post: by
1 post views Thread by Tor Inge Rislaa | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.