Results 1 to 17 of 17

Thread: ColorCode.dll Help

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    62

    ColorCode.dll Help

    Hi, I've been trying to get syntax hilighting for a RichTextBox.
    I am struggling trying to code it myself, so I looked around a bit, and found a cool .dll file called ColorCode.

    http://colorcode.codeplex.com/

    So I went into my project and imported the ColorCode.dll file. (Project>Add Reference)

    However, I don't know how to use it!?

    Is there anyone out there that has used this .dll file?

    How can I use it to get Syntax Hilighting in RichTextBox1?

    I have googled may times with no sucess.

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: ColorCode.dll Help

    the example on that page looks simple enough:

    vb Code:
    1. imports ColorCode
    2.  
    3. dim sourceCode as string = io.File.ReadAllText("/path/to/source/file")
    4. dim colorizedSourceCode  as string = new CodeColorizer().Colorize(sourceCode, Languages.CSharp)

    i haven't tried it but i'm guessing colorizedSourceCode will contain rtf

  3. #3

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    62

    Re: ColorCode.dll Help

    I have tried that code, but i don't know how i'm supposed to use it? thoes are Dim statements..?

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: ColorCode.dll Help

    assuming you want c# syntax highlighting:

    vb Code:
    1. richtextbox1.rtf = new CodeColorizer().Colorize(richtextbox1.text, Languages.CSharp)

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    62

    Re: ColorCode.dll Help

    ok, thanks for your help, but at run-time i get this message:
    "File format is not valid."
    and it highlights this line:
    Code:
    richtextbox1.rtf = new CodeColorizer().Colorize(richtextbox1.text, Languages.CSharp)
    I've tried changing it to:
    Code:
    Dim colorizedSourceCode As String = New CodeColorizer().Colorize(RichTextBox1.Text, Languages.CSharp)
            RichTextBox1.Rtf = colorizedSourceCode
    Thanks for your help, i really appreciate it!

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    25,464

    Re: ColorCode.dll Help

    i don't know any more about how ColorCode.dll works.
    hopefully someone else can help you.

  7. #7
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: ColorCode.dll Help


    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  8. #8

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    62

    Re: ColorCode.dll Help

    I have tried this:
    Code:
        Private Sub RichTextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RichTextBox1.TextChanged
            Dim sourceCode As String = My.Resources.Resources.IHttpModule
    
            Dim coloredCode As ColorCode.CodeColorizer = New ColorCode.
            CodeColorizer
    
            Dim colorizedSourceCode As String = coloredCode.Colorize(sourceCode, ColorCode.Languages.VbDotNet)
        End Sub
    Before, but could not understand, or get how to use the part at the top which says:
    Code:
    Dim sourceCode As String = My.Resources.Resources.IHttpModule

  9. #9
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: ColorCode.dll Help

    not sure I follow. do you have anything in your resources IHttpModule?

    by the look and conventions, IHttpModule is an interface. you are using a string to get sourcecode.

    you dont need it. sourcecode is just a string.... ie:

    Code:
    Dim myString as String = "hello"
    the above line is a source code snippet for VB code. what if you use the above string in "sourceCode"?

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  10. #10

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    62

    Re: ColorCode.dll Help

    ok, i see, but it's all Dim statements, when do you actually use any of the defined statements to effect the text in the RichTextBox?

    I tried:
    Code:
    RichTextBox1.Text = colorizedSourceCode
    Which was a mess.

    I also tried:
    Code:
    RichTextBox1.RTF = colorizedSourceCode
    but that crashed. ):

  11. #11
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: ColorCode.dll Help

    crashed? why would a string being assigned to a string crash? error messages please!

    you say when do you use it to actually reflect the changes? well, here:


    Dim colorizedSourceCode As String = coloredCode.Colorize(sourceCode, ColorCode.Languages.VbDotNet)
    richTextBox.Text = colorizedSourceCode


    now remember though, for the formatting to happen, the output from the colorizer MUST be have the correct syntax/formatting for RTF so the control can render it the way you want otherwise, it wont work.

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  12. #12

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    62

    Re: ColorCode.dll Help

    at run-time,


    and when trying:
    Code:
    Dim colorizedSourceCode As String = coloredCode.Colorize(sourceCode, ColorCode.Languages.VbDotNet)
            RichTextBox1.Text = colorizedSourceCode
    I get lots of funny charicters when I enter text, such as when entering "Imports" I get this in my RichTextBox:
    Code:
    <div style="color:Black;background-color:White;"><pre>
    s&lt;div style=<span style="color:#A31515;">&quot;color:Black;background-color:White;&quot;</span>&gt;&lt;pre&gt;
    t&amp;lt;div style=&lt;span style=<span style="color:#A31515;">&quot;color:#A31515;&quot;</span>&gt;&amp;quot;color:Black;background-color:White;&amp;quot;&lt;/span&gt;&amp;gt;&amp;lt;pre&amp;gt;
    r&amp;amp;lt;div style=&amp;lt;span style=&lt;span style=<span style="color:#A31515;">&quot;color:#A31515;&quot;</span>&gt;&amp;quot;color:#A31515;&amp;quot;&lt;/span&gt;&amp;gt;&amp;amp;quot;color:Black;background-color:White;&amp;amp;quot;&amp;lt;/span&amp;gt;&amp;amp;gt;&amp;amp;lt;pre&amp;amp;gt;
    o&amp;amp;amp;lt;div style=&amp;amp;lt;span style=&amp;lt;span style=&lt;span style=<span style="color:#A31515;">&quot;color:#A31515;&quot;</span>&gt;&amp;quot;color:#A31515;&amp;quot;&lt;/span&gt;&amp;gt;&amp;amp;quot;color:#A31515;&amp;amp;quot;&amp;lt;/span&amp;gt;&amp;amp;gt;&amp;amp;amp;quot;color:Black;background-color:White;&amp;amp;amp;quot;&amp;amp;lt;/span&amp;amp;gt;&amp;amp;amp;gt;&amp;amp;amp;lt;pre&amp;amp;amp;gt;
    p&amp;amp;amp;amp;lt;div style=&amp;amp;amp;lt;span style=&amp;amp;lt;span style=&amp;lt;span style=&lt;span style=<span style="color:#A31515;">&quot;color:#A31515;&quot;</span>&gt;&amp;quot;color:#A31515;&amp;quot;&lt;/span&gt;&amp;gt;&amp;amp;quot;color:#A31515;&amp;amp;quot;&amp;lt;/span&amp;gt;&amp;amp;gt;&amp;amp;amp;quot;color:#A31515;&amp;amp;amp;quot;&amp;amp;lt;/span&amp;amp;gt;&amp;amp;amp;gt;&amp;amp;amp;amp;quot;color:Black;background-color:White;&amp;amp;amp;amp;quot;&amp;amp;amp;lt;/span&amp;amp;amp;gt;&amp;amp;amp;amp;gt;&amp;amp;amp;amp;lt;pre&amp;amp;amp;amp;gt;
    m&amp;amp;amp;amp;amp;lt;div style=&amp;amp;amp;amp;lt;span style=&amp;amp;amp;lt;span style=&amp;amp;lt;span style=&amp;lt;span style=&lt;span style=<span style="color:#A31515;">&quot;color:#A31515;&quot;</span>&gt;&amp;quot;color:#A31515;&amp;quot;&lt;/span&gt;&amp;gt;&amp;amp;quot;color:#A31515;&amp;amp;quot;&amp;lt;/span&amp;gt;&amp;amp;gt;&amp;amp;amp;quot;color:#A31515;&amp;amp;amp;quot;&amp;amp;lt;/span&amp;amp;gt;&amp;amp;amp;gt;&amp;amp;amp;amp;quot;color:#A31515;&amp;amp;amp;amp;quot;&amp;amp;amp;lt;/span&amp;amp;amp;gt;&amp;amp;amp;amp;gt;&amp;amp;amp;amp;amp;quot;color:Black;background-color:White;&amp;amp;amp;amp;amp;quot;&amp;amp;amp;amp;lt;/span&amp;amp;amp;amp;gt;&amp;amp;amp;amp;amp;gt;&amp;amp;amp;amp;amp;lt;pre&amp;amp;amp;amp;amp;gt;
    I
    &amp;amp;amp;amp;amp;lt;/pre&amp;amp;amp;amp;amp;gt;&amp;amp;amp;amp;amp;lt;/div&amp;amp;amp;amp;amp;gt;
    &amp;amp;amp;amp;lt;/pre&amp;amp;amp;amp;gt;&amp;amp;amp;amp;lt;/div&amp;amp;amp;amp;gt;
    &amp;amp;amp;lt;/pre&amp;amp;amp;gt;&amp;amp;amp;lt;/div&amp;amp;amp;gt;
    &amp;amp;lt;/pre&amp;amp;gt;&amp;amp;lt;/div&amp;amp;gt;
    &amp;lt;/pre&amp;gt;&amp;lt;/div&amp;gt;
    &lt;/pre&gt;&lt;/div&gt;
    </pre></div>

  13. #13
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: ColorCode.dll Help

    ah

    this is HTML. RTF is NOT HTML

    this is your problem here

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  14. #14

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    62

    Re: ColorCode.dll Help

    eh, why would it turn to HTML?!
    any ideas on how to fix it?

  15. #15
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: ColorCode.dll Help

    well, not sure how the 3rd party API works (you should contact them since they made it!) but if it spits out HTML Then that probably is its job. unless there is some options/settings you need to specify, dont know
    there is nothing to "fix" if it was developed for HTML....

    why dont you take a look at the source code?

    http://colorcode.codeplex.com/Source...ist/changesets

    it helps if you read more and more about the product (just browsing the site) - it pretty much is designed for HTML. case closed really

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  16. #16

    Thread Starter
    Member
    Join Date
    Mar 2011
    Posts
    62

    Re: ColorCode.dll Help

    ):
    I will contact them.
    on their main page it says:

    "Language Support
    ColorCode supports the following languages:

    XML
    Java
    JavaScript
    SQL
    C#
    VB.NET
    ASPX (C#)
    ASPX (VB.NET)
    C++
    PHP
    PowerShell"

  17. #17
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: ColorCode.dll Help

    yes meaning that the syntax highlighter will work with code that is of the above languages (with the options specified in the configuration)

    it does work. but it is only for HTML. for example if you write (in a string) VB.NET or C# code and configure it for the respective language, it will syntax highlight it

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width