HTML Editor. Text Color Change

Please support our C# advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jul 2008
Posts: 9
Reputation: FullBjarne is an unknown quantity at this point 
Solved Threads: 0
FullBjarne FullBjarne is offline Offline
Newbie Poster

HTML Editor. Text Color Change

 
0
  #1
Jul 19th, 2008
Hello. I'm doing a html editor.
i want a function to the html editor that change the color on the text when I press a button. Example if I write this code in the html editors textbox:
<table><tr><td bgcolor = "abc123">hello</td></tr><table>
And then I press the button would it change the text color like this:
<table><tr><td bgcolor = "abc123">hello</td></tr></table>
What code should I use for that function?
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 509
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 88
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: HTML Editor. Text Color Change

 
0
  #2
Jul 19th, 2008
Hi, Use RichTextBox for editor. This control has SelectionColor property to change the color of the Selected Text.

But selecting should be done by you
KSG
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 9
Reputation: FullBjarne is an unknown quantity at this point 
Solved Threads: 0
FullBjarne FullBjarne is offline Offline
Newbie Poster

Re: HTML Editor. Text Color Change

 
0
  #3
Jul 19th, 2008
OK.
But i want it to change the color by it self. And when i press the button would the text color change and I want it to change all the letters color inside <>.
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 509
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 88
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: HTML Editor. Text Color Change

 
0
  #4
Jul 19th, 2008
Rich Text Box has KeyDown Event where you have to change the color by ur code when receiving '<' and '>' characters. This change the color when typing

If you want to set the color when press a button, then parse the text first, then apply the color to the text
KSG
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 9
Reputation: FullBjarne is an unknown quantity at this point 
Solved Threads: 0
FullBjarne FullBjarne is offline Offline
Newbie Poster

Re: HTML Editor. Text Color Change

 
0
  #5
Jul 19th, 2008
could you make the code for me?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 38
Reputation: farooqaaa is an unknown quantity at this point 
Solved Threads: 1
farooqaaa's Avatar
farooqaaa farooqaaa is offline Offline
Light Poster

Re: HTML Editor. Text Color Change

 
0
  #6
Jul 19th, 2008
I also need the code for this..?

Anyone know how to do it?
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 509
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 88
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: HTML Editor. Text Color Change

 
0
  #7
Jul 20th, 2008
Yes, I give simple example

  1. private char LastChar = ' ';
  2. private void richTextBox1_KeyPress(object sender, KeyPressEventArgs e)
  3. {
  4. if (LastChar == '<')
  5. {
  6. //Turn On Red after Pressing < character
  7. richTextBox1.SelectionColor = Color.Red;
  8. }
  9. if (e.KeyChar == '>')
  10. {
  11. //Turn Off Red Color
  12. richTextBox1.SelectionColor = richTextBox1.ForeColor;
  13. }
  14. LastChar = e.KeyChar;
  15. }
KSG
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 38
Reputation: farooqaaa is an unknown quantity at this point 
Solved Threads: 1
farooqaaa's Avatar
farooqaaa farooqaaa is offline Offline
Light Poster

Re: HTML Editor. Text Color Change

 
0
  #8
Jul 20th, 2008
Hmm... That won't work well. We need to use Regular expressions. Anyone familiar with it?
Reply With Quote Quick reply to this message  
Join Date: Feb 2008
Posts: 509
Reputation: selvaganapathy is an unknown quantity at this point 
Solved Threads: 88
selvaganapathy's Avatar
selvaganapathy selvaganapathy is offline Offline
Posting Pro

Re: HTML Editor. Text Color Change

 
1
  #9
Jul 20th, 2008
The above code that i posted only works when type the tags

When you want change the color by pressing button. I am not familiar with Regular Expression, still a try.
Try this
  1. private void button1_Click(object sender, EventArgs e)
  2. {
  3. Regex regex = new Regex(@"(<\b[^>]*>)|(</\b[^>]*>)", RegexOptions.IgnoreCase | RegexOptions.Compiled);
  4.  
  5. for (Match match = regex.Match(richTextBox1.Text ); match.Success; match = match.NextMatch())
  6. {
  7. richTextBox1.Select ( match.Index +1, match.Value.Length -2);
  8. richTextBox1.SelectionColor = Color.Red ;
  9. richTextBox1.DeselectAll ();
  10. }
  11. }
Last edited by selvaganapathy; Jul 20th, 2008 at 8:13 am.
KSG
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 9
Reputation: FullBjarne is an unknown quantity at this point 
Solved Threads: 0
FullBjarne FullBjarne is offline Offline
Newbie Poster

Re: HTML Editor. Text Color Change

 
0
  #10
Jul 20th, 2008
It didn't work for me, I've got five errors.
Last edited by FullBjarne; Jul 20th, 2008 at 8:38 am.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC