Results 1 to 6 of 6

Thread: Code editor(Help)

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    47

    Code editor(Help)

    I'm trying to make an HTML editor for my school project.

    I need help color coding the text so if they type <html>, <b>, <body> in any case it'll color code it to turn blue.

  2. #2
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Code editor(Help)

    How much of this do you need to do yourself?

    There's a great library out there for this, with tons of examples, FastColoredTextBox, but if it's a school project it might not be appropriate. Anyway, this is the one I'd recommend.

    Otherwise, writing your own TextBox is probably out of the question, so you'd be pretty much stuck with a RichTextBox in that case, which is terrible for highlighting.

  3. #3

    Thread Starter
    Member
    Join Date
    Dec 2011
    Posts
    47

    Re: Code editor(Help)

    Yeah that won't work for me.

    I need to make it so if someone types < it changes the forecolor to blue, and if they finish it with > then it makes the color black again.

  4. #4
    Junior Member
    Join Date
    Mar 2008
    Posts
    31

    Re: Code editor(Help)

    they have some gui components for that but you could just show them web browser control and feed it html code and keep refreshing the preview everytime they type code.

  5. #5
    Hyperactive Member DavesChillaxin's Avatar
    Join Date
    Mar 2011
    Location
    WNY
    Posts
    451

    Re: Code editor(Help)

    You really could use a RichTextBox easily. I did this a few years ago for my AIM client software I created. When your typing your keys check for ">", while using .SelColor() to change the color of the text you want. Everytime the user types a ">" (that isn't enclosed in quotes) should signify there is a matching "<" to go with it. Find both, and select the angle brackets and everything in between and set the color with .SelColor(). If you can't find a matching "<" then the user mistyped and no colors should be changed.


    There will be a lot of work to do to make sure everything is handled correctly for whatever the user might type in the RichTextBox, but that's usually the case for any word processing. There are loads of condition that have to be taken into consideration. The biggest being quotes, where you should always be checking for open and closing quotes to not highlight anything within them that may be key words. While also coloring the whole quoted statement if you choose too.

    Unfortunately as it has been said before, this process can get slow-based on the RichTextBox's performance.. If you want and know the way, only color whats visible. This could speed things up dramatically.
    Last edited by DavesChillaxin; Feb 9th, 2012 at 03:59 PM.
    Please rate if my post was helpful!
    Per favore e grazie!




    Code Bank:
    Advanced Algebra Class *Update | True Gradient Label Control *Dev | A Smarter TextBox *Update | Register Global HotKey *Update
    Media Library Beta *Dev | Mouse Tracker (Available in VB.net and C#.net) *New | On-Screen Numpad (VB.net) *New

  6. #6
    Stack Overflow mod​erator
    Join Date
    May 2008
    Location
    British Columbia, Canada
    Posts
    2,824

    Re: Code editor(Help)

    Quote Originally Posted by Slushi View Post
    Yeah that won't work for me.

    I need to make it so if someone types < it changes the forecolor to blue, and if they finish it with > then it makes the color black again.
    Specifically, though, why won't it work for you? It can easily do what you describe, not just what's shown in the examples.

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