|
Another fix:
If there are to many items in the dropdownlist, you cant get to see then all.
///
/// Gets or sets the index of the selected item.
///
/// <value>The index of the selected.
internal int SelectedIndex
{
get
{
if (lstCompleteItems.SelectedIndices.Count == 0)
{
return -1;
}
return lstCompleteItems.SelectedIndices[0];
}
set
{
//Find item to select.
ListViewItem anItem = lstCompleteItems.Items[value];
anItem.Selected = true;
//Scroll item into view
lstCompleteItems.TopItem = anItem;
}
}
|
|
|
|
|
Hi I use this:
_editBox.HighlightDescriptors.Add(
new HighlightDescriptor("test", Color.Blue, null, DescriptorType.Word, DescriptorRecognition.WholeWord, true));
But when I open a file with this in it:
function foo()
{
return test
}
it does not colorize the text.
Also if I do this:
1. Type a double quote: "
2. Ctrl-Space
3. Choose "test" from auto completion dropdown
4. Press Enter
It inserts "test" correctly but removes the double quote.
What am I doing wrong?
|
|
|
|
|
Nice work i ahve engage it in my Application its very useful
thanks
|
|
|
|
|
txtbox_keyUp (null,null) what can i put here so it wont be null anymore, this makes me problem with your component syntax highlight
|
|
|
|
|
If i enter the text like this the comment is not highlited
Outsidecomment/*Indide comment*/
Note that there is no space between Ouside Comment and /*
This is the case with string literals too.
Suneel
|
|
|
|
|
i have another problem now...
i just want to open a plain text file into my Highlight textbox. but it says the type is invalid
if i save some text and i open the file i see that its saved with colors in it...
how can i save and load my files as plain text?
please help,
RoeltjE
|
|
|
|
|
hey, im in the C# thing for a few weeks now.
i have a problem with the highlighting textbox... <_<
what i do is:
i import the highlighting textbox project
i make a new highlight textbox
i add using UrielGuy.SyntaxHighlightingTextBox;
then i add:
private void Form1_Load(object sender, System.EventArgs e)<br />
{<br />
TextBox.Seperators.Add(' ');<br />
TextBox.Seperators.Add('\r');<br />
TextBox.Seperators.Add('\n');<br />
TextBox.Seperators.Add(',');<br />
TextBox.Seperators.Add('.');<br />
TextBox.Seperators.Add('-');<br />
TextBox.Seperators.Add('+');<br />
TextBox.HighlightDescriptors.Add(new HighlightDescriptor("Hello", Color.Red, null, DescriptorType.Word, DescriptorRecognition.WholeWord, true));<br />
TextBox.HighlightDescriptors.Add(new HighlightDescriptor("Hellofatime", Color.Green, null, DescriptorType.Word, DescriptorRecognition.WholeWord, true));<br />
TextBox.HighlightDescriptors.Add(new HighlightDescriptor("Helsinky", Color.Maroon, null, DescriptorType.Word, DescriptorRecognition.WholeWord, true));<br />
TextBox.HighlightDescriptors.Add(new HighlightDescriptor("World", Color.Blue, null, DescriptorType.Word, DescriptorRecognition.WholeWord, true));<br />
TextBox.HighlightDescriptors.Add(new HighlightDescriptor("/*", "*/", Color.Magenta, null, DescriptorType.ToCloseToken, DescriptorRecognition.StartsWith, false)); <br />
}
but when i test it (it works untill i press space or an other seperator) then it says:
string curToken = tokens[tokenCounter++];
Index was outside the bounds of the array.
please help me! i'd really appreciate it!
Greetz,
RoeltjE
EDIT: WHAAAAA I GOT IT!!!
IM SOOOO HAPPY!!! I WORKED 2 DAYS ON IT TO MAKE IT WORK!
the problem:
i forgot to add this:
this.Load += new System.EventHandler(this.Form1_Load);
this means it had no seperators nor words that could be highlighted
ahhh im sooo happy!
-- modified at 10:45 Sunday 30th April, 2006
|
|
|
|
|
This is a very nice implementation for the highlighted text editor.
keep up the good work.
C:\>csc *.cs
Microsoft (R) Visual C# .NET Compiler
error CS2001: Source file 'brains.cs' could not be found
fatal error CS2008: No [brains.cs] specified
C:\>
|
|
|
|
|
Hi,
I didn't find any sample code in the test download. I would like to see how to use this control from my C# code. Is there any sample code available?
Thanks!
|
|
|
|
|
Hi !!!
I like your textbox with syntax highlighting and other beautiful functions. It was easy to use, but your code was the biggest calamity that I've ever seen. You have bad 'code design'. Sorry about that, but you shall really change your 'code design'.
Ciao, KNOX.
-:KNOX:-
|
|
|
|
|
Hey, Very nice work !
But I have litte problem with encoding or somthig else I dont know ?! Sorry I'm newbee in C#,
When I create normal RichTextBox, I can type any Windows-1250 chars like ( ąćźćććźęćż ) but when I create Syntax highlighting textbox all chars, this same chars looks like this - ¹æŸæææŸêæ¿ Maybe I do somthign wrong ? Can somebody help me please or sugest what I do wrong ?
|
|
|
|
|
Hi
Ive got an exception "IndexOutOfRangeException" in method "OnTextChanged" in class "SyntaxHighlightingTextBox" when there is no seperators chosen on the control.
Maybe you should handle it somehow.
Besides that - great code snippet. Very useful.
|
|
|
|
|
So far the controls is really good. But I have run into a problem with defining custom fonts for my descriptors. If I add a custom font to even ONE descriptor the entire text is cleared. What can be cause of this?
|
|
|
|
|
This reply may be far too late to help you, but hopefully it will help others who have run into this problem.
It looks like there is a '{' character missing at the start of any new fonts added to the font table. To fix this, I made the following modifications to the code:
- In the OnTextChanged method of the SyntaxHighlightingTextBox class, search for the line with the comment "//Adding RTF header". Remove the last '{' from this line so that it reads:
sb.Append(@"{\rtf1\fbidis\ansi\ansicpg1255\deff0\deflang1037{\fonttbl");
- In the AddFontToTable method of the same class, add a '{' to the start of the append so that it reads:
sb.Append(@"{\f").Append(counter).Append(@"\fnil\fcharset0").Append(font.Name).Append(";}");
This seems to work for me. Good luck!
|
|
|
|
|
If you set this.Enabled = false before doing the highlighting and set it back to this.Enabled = true followed by this.Focus() followed by the SEtScrollPos(), you get a lot less flicker. The scrollbars stop moving too.
so something like
<br />
this.Enabled = false;<br />
<br />
{do processing here}<br />
<br />
this.Enabled = true;<br />
this.Focus();<br />
this.SetScrollPos(point);<br />
Thanks for the awesome article.
Cheers,
Aditya
|
|
|
|
|
Hey, this is a really cool solution to something that I have been looking for ages. Great job!!!
I'm just having a couple of problems, that someone else also mentioned. One is with string literals.
I'm using your highlighting textbox to highlight T-SQL code. In T-SQL code, anything contained within a string is colored in red. As follows:
select 'this is a test'
Everything in between the two single-quotes (including the quotes) should be in red.
So I used the following line (note that I'm using your class within a vb.net application):
txtTest.HighlightDescriptors.Add(New HighlightDescriptor("'", "'", Color.Red, Nothing, DescriptorType.ToCloseToken, DescriptorRecognition.StartsWith, False))<br />
The problem seems to be that the close token "'" is the same as the open token. If I chose a different close token (for example, "'." ) it works fine but then I'd need to do:
select 'this is a test'.
The other small problem I'm having is this.
if I add a seperator, (for example "/" or "*") then the code below doesn't work and it won't highlight anything in between the opening and closing tokens.
It looks like I cannot add a seperator that uses the the same characters that are contained in my opening or closing tokens below:
txtTest.HighlightDescriptors.Add(New HighlightDescriptor("/*", "*/", Color.Green, Nothing, DescriptorType.ToCloseToken, DescriptorRecognition.StartsWith, False))<br />
Other than those two small problems it's really great. The best solution I have found so far.
If you need any other details let me know. It could even be that I'm using vb.net and not c#.
Thanks
|
|
|
|
|
Hey.
First of all, thanks for the input.
I'm not next to the code at the moment so I can't try to reproduce your problem, but try downloading the latest version. I've fixed a problem just like the one you've described.
Regards,
Uriel Guy
|
|
|
|
|
I'm still getting the same problem but I can't be certain that I have the latest version of the code. I just downloaded it from here - is there somewhere else it can be downloaded from?
I added the following line to the Form1_Load event in Tester:
shtb.HighlightDescriptors.Add(new HighlightDescriptor("'", "'", Color.Red, null, DescriptorType.ToCloseToken, DescriptorRecognition.StartsWith, false));
It still doesn't work. I noticed that slightly further up in the Form1_Load event you have commented out the following lines:
If I uncomment these lines then your HighLightDescriptor with starting token, "/*" and finishing token, "*/", stops working. So maybe I have an older version of the code.
|
|
|
|
|
Any word on this and whether there is a later version of the code that provides a fix for this problem?
thanks
|
|
|
|
|
You are correct that there is a bug in Uri's code concerning close tokens that are the same as the open token I just used the control today (thanks, Uri ) for highlighting some C# code, so I fixed the problem. Replace the 'case' shown here and you should be in business:
case DescriptorType.ToCloseToken:
{
int closeStart = i + hd.Token.Length;
while((line.IndexOf(hd.CloseToken, closeStart) == -1) && (lineCounter < lines.Length))
{
sb.Append(line.Remove(0, i));
lineCounter++;
if (lineCounter < lines.Length)
{
AddNewLine(sb);
line = lines[lineCounter];
i = closeStart = 0;
}
else
i = closeStart = line.Length;
}
int closeIndex = line.IndexOf(hd.CloseToken, closeStart);
if (closeIndex != -1)
{
sb.Append(line.Substring(i, closeIndex + hd.CloseToken.Length - i) );
line = line.Remove(0, closeIndex + hd.CloseToken.Length);
tokenCounter = 0;
tokens = mCaseSensitive ? line.Split(separators) : line.ToUpper().Split(separators);
SetDefaultSettings(sb, colors, fonts);
i = 0;
}
break;
}
|
|
|
|
|
Thanks for the reply Ken.
I haven't had a close look at the code yet (I don't know much c# unfortunately) but I'm going to see if I can fix the performance problems that someone else mentioned.
When dealing with large amounts of text, performance slows down. I suspect that the whole document is being parsed when perhaps it would only be necessary to parse the current line that the cursor is on.
|
|
|
|
|
I have applied the fix you showed, but it still doesn't seem to work.
How do you define the HighlightDescriptor for string literals?
|
|
|
|
|
Strange - that fixed the problem for me. It's in that one case where the bug was - it wasn't skipping past the open token before searching for the close token, so if they were the same it would treat the open also as a close.
Anyway, it works for me now. Here's an example of using it for double & single quotes:
textBox.HighlightDescriptors.Add(new HighlightDescriptor("\"", "\"", Color.Maroon, null, DescriptorType.ToCloseToken, DescriptorRecognition.StartsWith, false));
textBox.HighlightDescriptors.Add(new HighlightDescriptor("'", "'", Color.Olive, null, DescriptorType.ToCloseToken, DescriptorRecognition.StartsWith, false));
|
|
|
|
|
Got it! I had added ' and " as separators, and that apparently broke the highlight descriptors.
|
|
|
|
|
Great job, but i've got a one problem with this code. If you escape the the " or ' like "this \"is\" a string" or 'this \'is\' a string' the color shouldn't stop at the word is.
|
|
|
|
|