Like in VB, C++ and most languages, what would be the fastest way to syntax highlight? I will be using a Rich Text Box since a textbox wont cut it, so an RTB is my only other option unless someone else has a better idea? what i am trying to do is say the user types this:
If X == y then
cout << "wxyz"
endif
I would like to say make the if red, the then red, and then endif red, and the cout blue, and the "wxyz" green. but is there an easy way to do this so the screen will not flicker. because to change the color of a portion of text in a rtb you have to highlight the text and then change it. so my question is, how does M$ do it?
You would need to list all the unique keywords , and check them in the textchang event of the RTF . I think , RegularExpressions would help you in this regard .
yeah but every time i go through the text change event, it's going to eat up a lot of cpu time to check that, too bad I can not break the rtb text up into lines. Then just search just that line. If they pasted something into the file then i would be screwed but, hmm, is there an easy way to break the rtb.text up into lines because i think you can only access the text as one whole part. what i am trying to do i guess is if the user types this
line 1
line 2
line 3
and the user just got done typeing on line 2 check line 2, errr just another problem to solve.
Originally posted by deoblo1 Well to access the lines i can just use rtb.lines(rtb.lines.length() - 1) to get the last line, and then ill figure the rest out...
I'm doing a similar thing with syntax highlighting.... this code would access the previous line but using the when text changes event would still slow everything down...
If you come up with a solution, please post
I'm still working on other things, havn't gotten up to the part to impliment syntax highlighting
If you use the TextChanged event you may want to only check for highlighting on spaces or enters since that means a full word was completed and would save several attempts on partial words during typing. Another optimization you could do is to store the last spot in the text that you checked and only check from there on in future checkes. One thing to remember if you use any of these is to make exceptions for cut and paste. Maybe add tab to the list of triggers to check on.
I have even thought about writing my own control in c++ and customizing it, but I dont know where to start? kasracer, if you think that would be an option let me know, maybe if we put our heads together we can figure something out...
Originally posted by deoblo1 I have even thought about writing my own control in c++ and customizing it, but I dont know where to start? kasracer, if you think that would be an option let me know, maybe if we put our heads together we can figure something out...
I'm not even sure.... You could always ame some sort of loop that comes in when the text box loads and run a loop that does asbsolutely nothing until the user presses enter then it checks the previous line... but if the user goes up to the top and changes something, I'm not sure how that would work.
I have most of it figured out in my head, i just dont know how to create the control that will go on the form. and how to accept user input etc. I just chose c++ b/c it is faster, and i could drop down and use assembly if need be.
Originally posted by deoblo1 I have most of it figured out in my head, i just dont know how to create the control that will go on the form. and how to accept user input etc. I just chose c++ b/c it is faster, and i could drop down and use assembly if need be.
Yeah C++ is faster, but if incorporated into VB, it may be slowed down slightly. That and you'd have to use a Dynamic Link Library, which is something I've never done in C++..... never really had a reason too...
was just thinking about making my own text box control, as for the handeling of the keypresses that is no problem, it's the cuts and pastes, and the mouse clicking i would have a problem with. But i was thinking of designing a control speciflicly for syntax highlighting. I figure if i write my own i can get around the problems of the rich text box. have a control that is designed to search for specific words, or char's and highlight them. But my problem like i said is the user input and output, and if it would work...
I thought about just turning the control form white, and going from there and just "playing" till i got something working, but i was hoping someone would give me a little direction on the best way. I found this Site it showes that an activex control is quite simple, but it's just getting it to work.
I just got an idea... when you press enter, change text at the top of a document, or cut and paste, where is the I-Beam curser? it's right there on that line!
You could probably mark which line the I-Beam curser is on and when it moves to another line, check the previous line it was on and then put the new line's address into a variable and repeat
That sounds like it would work and wou8ldn't use alot of cpu power... hmmm
yeah u would have to put that in the rtb's keypress event (if it has one, i am not sure) and you would also have to have it in the mouse click event. but not bad thinking.
I wouldn't want to limit myself to on keypress or anything like that, I just need a loop to always run which checks to see where the I-Beam is, if it's the same line as stored in the variable, then it does nothing or if it gets changed it runs a function which checks the line before then puts the new line's number in the variable.
Rinse and repeat. Now... where could I put the loop? I am thinking of making sure the textbox always has focus and then doing the loop when it has focus.
dont think you can create your own event, i doubt it. but I just looked into created an activex control in c++ and i realized why I have never done it, i dont know how to program windows apps in c++, i just know how to make dos apps. so yeah it's back to vb.net.
Originally posted by deoblo1 dont think you can create your own event, i doubt it. but I just looked into created an activex control in c++ and i realized why I have never done it, i dont know how to program windows apps in c++, i just know how to make dos apps. so yeah it's back to vb.net.
Working with the windows API in C++ just scusk...
This is basicly the main and only reason I went to VB .NET. I still program things in C++, but I don't do any type of GUIs.
Later I'm going to try what I suggested, I'll see how it works.