Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I optimize this or is there a better way to do it?(HTML Syntax Highlighter)
    text
    copied!<p>I have made a HTML syntax highlighter in C# and it works great, but there's one problem. First off It runs pretty fast because it syntax highlights line by line, but when I paste more than one line of code or open a file I have to highlight the whole file which can take up to a minute for a file with only 150 lines of code. I tried just highlighting visible lines in the richtextbox but then when I try to scroll I can't it to highlight the new visible text. Here is my code:(note: I need to use regex so I can get the stuff in between &lt; &amp; > characters)</p> <p>Highlight Whole File:</p> <pre><code> public void AllMarkup() { int selectionstart = richTextBox1.SelectionStart; Regex rex = new Regex("&lt;html&gt;|&lt;/html&gt;|&lt;head.*?&gt;|&lt;/head&gt;|&lt;body.*?&gt;|&lt;/body&gt;|&lt;div.*?&gt;|&lt;/div&gt;|&lt;span.*?&gt;|&lt;/span&gt;|&lt;title.*?&gt;|&lt;/title&gt;|&lt;style.*?&gt;|&lt;/style&gt;|&lt;script.*?&gt;|&lt;/script&gt;|&lt;link.*?/&gt;|&lt;meta.*?/&gt;|&lt;base.*?/&gt;|&lt;center.*?&gt;|&lt;/center&gt;|&lt;a.*?&gt;|&lt;/a&gt;"); foreach (Match m in rex.Matches(richTextBox1.Text)) { richTextBox1.Select(m.Index, m.Value.Length); richTextBox1.SelectionColor = Color.Blue; richTextBox1.Select(selectionstart, -1); richTextBox1.SelectionColor = Color.Black; } richTextBox1.SelectionStart = selectionstart; } private void pasteToolStripMenuItem_Click(object sender, EventArgs e) { try { LockWindowUpdate(richTextBox1.Handle);//Stops text from flashing flashing richTextBox1.Paste(); AllMarkup(); }finally { LockWindowUpdate(IntPtr.Zero); } } </code></pre> <p>I want to know if there's a better way to highlight this and make it faster or if someone can help me make it highlight only the visible text.</p> <p>Please help. :) Thanks, Tanner.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload