|
Thanks for your project. It's very useful!
|
|
|
|
|
I've converted to VB.net with #Develop and fixed it
Public Sub SyntaxAll(ByVal _RichTextBox As RichTextBox)
Try
Dim _SelectionStart As Integer = _RichTextBox.SelectionStart
Dim _SelectionLength As Integer = _RichTextBox.SelectionLength
Dim _SelectionColor As Color = _RichTextBox.ForeColor
Dim _SelectionFont As Font = _RichTextBox.Font
For i As Integer = 0 To _RichTextBox.Lines.Length - 1
For Each _HighlightMatch As HighlightMatch In Matches
Dim _MatchCollection As MatchCollection = New Regex(_HighlightMatch.MatchString).Matches(_RichTextBox.Lines(i))
If _MatchCollection.Count > 0 Then
LockWindowUpdate(_RichTextBox.Handle)
For Each _Match As Match In _MatchCollection
Dim _StartIdex As Integer = _RichTextBox.GetFirstCharIndexFromLine(i)
_RichTextBox.[Select](_StartIdex + _Match.Index, _Match.Length)
_RichTextBox.SelectionColor = _HighlightMatch.MatchColor
_RichTextBox.SelectionFont = _HighlightMatch.MatchFont
_RichTextBox.SelectionBackColor = _HighlightMatch.MatchBackColor
Next
End If
_RichTextBox.SelectionStart = _SelectionStart
_RichTextBox.SelectionLength = _SelectionLength
_RichTextBox.SelectionColor = _SelectionColor
_RichTextBox.SelectionFont = _SelectionFont
LockWindowUpdate(IntPtr.Zero)
_RichTextBox.Invalidate()
Next
Next
Catch
End Try
End Sub
|
|
|
|
|
I would also like to use it in my project. I could see a similar message related to License issue but did'nt find any reply. Please can somebody help on what is the License.Would appreciate any help as its a bit urgent.
|
|
|
|
|
I also want to use it.Well, I AM USING WITHOUT RESTRICTIONS. But I'll give some credit.
|
|
|
|
|
This tool is amazing, thank you for your great work!
I like to know if I can highlight a text that is between the same character.
Ex:
When I use
shTextBox.HighlightDescriptors.Add(new HighlightDescriptor("'", "*", Color.Purple, null, DescriptorType.ToCloseToken, DescriptorRecognition.StartsWith, false))
the text between ' and * appear in purple
but when I want to use the same character it want work, like this
shTextBox.HighlightDescriptors.Add(new HighlightDescriptor("'", "'", Color.Purple, null, DescriptorType.ToCloseToken, DescriptorRecognition.StartsWith, false))
Is there any way to do this? I tried to change the DescriptorRecognition in all combinations and add no positive result.
regards,
Pedro Mendonça
|
|
|
|
|
Hi,
i had the same requirement highlighting between two ' or two quotes. I found a way to fix it in the code but i give no guarantee that it will work all the time:
You have to replace code in the Method
OnTextChangedEx in switch
//Print text affected by this descriptor.
switch (hd.DescriptorType) in the case
case DescriptorType.ToCloseToken:
Replace the code block
if (line.IndexOf(hd.CloseToken, i) != -1)
{
sb.Append(line.Substring(i, line.IndexOf(hd.CloseToken, i) + hd.CloseToken.Length - i) );
line = line.Remove(0, line.IndexOf(hd.CloseToken, i) + hd.CloseToken.Length);
tokenCounter = 0;
tokens = mCaseSesitive ? line.Split(sperators) : line.ToUpper().Split(sperators);
SetDefaultSettings(sb, colors, fonts);
i = 0;
}
by this code:
if (line.IndexOf(hd.CloseToken, i) != -1)
{
int singleCharExpand = 0;
if (hd.CloseToken.Length == 1 && line.IndexOf(hd.CloseToken, i+1) != -1)
{
singleCharExpand = 1;
}
sb.Append(line.Substring(i, line.IndexOf(hd.CloseToken, i + singleCharExpand) + hd.CloseToken.Length - i));
line = line.Remove(0, line.IndexOf(hd.CloseToken, i + singleCharExpand) + hd.CloseToken.Length);
tokenCounter = 0;
tokens = mCaseSesitive ? line.Split(sperators) : line.ToUpper().Split(sperators);
SetDefaultSettings(sb, colors, fonts);
i = 0;
}
|
|
|
|
|
You can use Chr with ASCII code 34. Because you'll never do:
this.Text = """
|
|
|
|
|
Thanks mate. This is cool.
|
|
|
|
|
Good morning.
I wonder what the licenses imposed on the artifact produced in this article. It is opensource, free or simply does not have license? I am wanting to use it in a small project at my university and I need to explain and cite properly.
Could you help me?
Att,
Victon Malcolm Rodrigues
|
|
|
|
|
How to compile this codes?
|
|
|
|
|
Goto Solution Explorer
Right Click Tester > Set as Start up Project > Press Ctrl + F5 > Bingo! Done!
|
|
|
|
|
I am using this code in my project and sloved this SetAutoCompleteItems()
i changed code in two function
1)public bool AcceptAutoCompleteItem()
2)private void SetAutoCompleteItems()
private void SetAutoCompleteItems()
{
mAutoCompleteForm.Items.Clear();
string filterString = "";
if (mFilterAutoComplete)
{
int filterTokenStartIndex = Text.LastIndexOfAny(mSeperators.GetAsCharArray(), Math.Min(SelectionStart, Text.Length - 1))+1;
int filterTokenEndIndex= Text.LastIndexOfAny(mSeperators.GetAsCharArray(), SelectionStart-1)+1;
if(filterTokenStartIndex==filterTokenEndIndex)
{filterTokenEndIndex=-1;
filterTokenEndIndex= Text.IndexOfAny(mSeperators.GetAsCharArray(), SelectionStart)+1;
}
if (filterTokenEndIndex == 0)
{
filterTokenEndIndex = Text.Length;
filterString = Text.Substring(filterTokenStartIndex, filterTokenEndIndex - filterTokenStartIndex).ToUpper();
}
else
{
try
{
if(filterTokenStartIndex-filterTokenEndIndex<0)
{
filterString=" ";
}
else
{
filterTokenStartIndex=filterTokenStartIndex-1;
filterString = Text.Substring(filterTokenEndIndex, filterTokenStartIndex-filterTokenEndIndex).ToUpper();
if(filterString==" "||filterString=="\n")
filterString="";
}
}
catch
{
filterString=" ";
}
}
}
foreach (HighlightDescriptor hd in mHighlightDescriptors)
{
if (hd.Token.ToUpper().StartsWith(filterString) && hd.UseForAutoComplete)
{
mAutoCompleteForm.Items.Add(hd.Token);
}
}
mAutoCompleteForm.UpdateView();
}
private void SetAutoCompleteSize()
{
mAutoCompleteForm.Height = Math.Min(
Math.Max(mAutoCompleteForm.Items.Count, 1) * mAutoCompleteForm.ItemHeight + 4,
mAutoCompleteForm.MaximumSize.Height);
}
and also in
public bool AcceptAutoCompleteItem()
{
if (mAutoCompleteForm.SelectedItem == null)
{
return false;
}
int curTokenStartIndex = Text.LastIndexOfAny(mSeperators.GetAsCharArray(), Math.Min(SelectionStart, Text.Length - 1))+1;
int curTokenEndIndex= Text.LastIndexOfAny(mSeperators.GetAsCharArray(), SelectionStart-1)+1;
if(curTokenStartIndex==curTokenEndIndex)
{
curTokenEndIndex= Text.IndexOfAny(mSeperators.GetAsCharArray(), SelectionStart)+1;
}
if (curTokenEndIndex == 0)
{
curTokenEndIndex = Text.Length;
SelectionStart = Math.Max(curTokenStartIndex, 0);
SelectionLength = Math.Max(0,curTokenEndIndex - curTokenStartIndex);
SelectedText = mAutoCompleteForm.SelectedItem;
SelectionStart = SelectionStart + SelectionLength;
SelectionLength = 0;
}
else
{
curTokenStartIndex=curTokenStartIndex-1;
SelectionStart = Math.Max(curTokenEndIndex, 0);
SelectionLength = Math.Max(0,curTokenStartIndex-curTokenEndIndex );
SelectedText = mAutoCompleteForm.SelectedItem;
SelectionStart = SelectionStart + SelectionLength;
SelectionLength = 0;
}
HideAutoCompleteForm();
return true;
}
|
|
|
|
|
|
Everything works perfectly fine until I add new lines, and return to previous blank lines and press "ctrl + space" When I do, I get an indexing error on filterString because filterTokenStartIndex becomes a +1 past the selection start and filtertokenEndIndex is the value for SelectionStart
Any way around this?
|
|
|
|
|
Hi! Does anyone know of a web version of this?
Thanks!
R
GaltSalt
maker of .Net thingys
|
|
|
|
|
Hello, nice textbox
I'm using it in a HTML editor, and when a use types <a href="example.com">visit example.com</a> and i set that there should be a highlighter from < to >, .com gets also highlighted.
-- Modified Wednesday, June 2, 2010 2:51 PM
|
|
|
|
|
Hi guys, What tweak do I need to do to allow comments (//) and multi-line comments (/*) whilst still allowing the seperators * and /.
I tried changing the seperators to use strings instead of chars but I failed, lol.
Any advice/ help would be appreciated.
|
|
|
|
|
Hi,
at first: Well done! It matches my needs, I think. But I had some issues with highlighting existing Text (it didn't highlight). After I pressed a key, everything worked. I fixed it by overriding this property:
public override string Text
{
get
{
return base.Text;
}
set
{
base.Text = value;
OnTextChanged(null);
}
}
Greetings,
nd
|
|
|
|
|
Thank you for sharing this nice highlighting textbox.
I played today a little bit with regex to highlight xml syntax and this is the result:
#region XML syntax highlighting like in Visual Studio
shtb.AddHighlightDescriptor( DescriptorRecognition.RegEx, ".*", DescriptorType.Word, Color.Black, tmp, false );
shtb.AddHighlightDescriptor( DescriptorRecognition.RegEx, "<.[^>]+>", DescriptorType.Word, Color.Brown, tmp, false );
shtb.AddHighlightDescriptor( DescriptorRecognition.RegEx, "<!--.[^>]*-->", DescriptorType.Word, Color.Green, tmp, false );
shtb.AddHighlightDescriptor( DescriptorRecognition.RegEx, @"\s(\w)+=", DescriptorType.Word, Color.OrangeRed, tmp, false );
shtb.AddHighlightDescriptor( DescriptorRecognition.RegEx, @"<!--|-->|<\?|\?>", DescriptorType.Word, Color.Blue, tmp, false );
shtb.AddHighlightDescriptor( DescriptorRecognition.RegEx, "<|>", DescriptorType.Word, Color.Blue, tmp, false );
shtb.AddHighlightDescriptor( DescriptorRecognition.RegEx, "</|/>", DescriptorType.Word, Color.Blue, tmp, false );
#endregion XML syntax highlighting like in Visual Studio
OK, it's not perfect, but maybe usefull for somebody.
Better suggestions are welcome.
Regards
Chris
|
|
|
|
|
Looking for age! ... really cool ... Thanks ^_^
|
|
|
|
|
|
temp. fix is to add the line like this but is not perfect as you will need to add SPACE before the qoute start as here ("lwkkjwe") all is red but if ( "TXT") only "txt"
rtb_Editor.HighlightDescriptors.Add(new HighlightDescriptor("\"", "\"", Color.Red, null, DescriptorType.ToCloseToken, DescriptorRecognition.Contains, false));
DescriptorRecognition.StartsWith to Contains
see pic here http://www.psymail.net/02.gif[^]
|
|
|
|
|
Um.. I'm kind of a newbie here. I've worked with C# for just about a month.
How would I go about inserting this to my rich text box? Which files do I import into my project and what must I do to make this function on my own rich text box?
Sorry if I overlooked this.
|
|
|
|
|
The source code provided is complete. Download it and extract to a sensible location, then import into your project.
Chris Bray
|
|
|
|
|
To avoid the unsafe keyword you can use GCHandle.
Use this code:
private Win32.POINT GetScrollPos()
{
var res = new Win32.POINT();
var hPoint = GCHandle.Alloc(res, GCHandleType.Pinned);
var ptr = hPoint.AddrOfPinnedObject();
Win32.SendMessage(Handle, Win32.EM_GETSCROLLPOS, 0, ptr);
hPoint.Free();
return res;
}
private void SetScrollPos(Win32.POINT point)
{
var hPoint = GCHandle.Alloc(point, GCHandleType.Pinned);
var ptr = hPoint.AddrOfPinnedObject();
Win32.SendMessage(Handle, Win32.EM_SETSCROLLPOS, 0, ptr);
hPoint.Free();
}
...and it works!
FPF
|
|
|
|
|