|
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
|
|
|
|
|
private void lstCompleteItems_SelectedIndexChanged(object sender, System.EventArgs e)
{
if (lstCompleteItems.SelectedItems.Count > 0) lstCompleteItems.EnsureVisible(lstCompleteItems.SelectedItems[0].Index);
}
ScrollBars work!
|
|
|
|
|
Can I use your control in my commercial project?
|
|
|
|
|
shtb.HighlightDescriptors.Add(new HighlightDescriptor("[", "]", Color.Green, null, DescriptorType.ToCloseToken, DescriptorRecognition.StartsWith, false));
does work well, but
shtb.HighlightDescriptors.Add(new HighlightDescriptor("{", "}", Color.Green, null, DescriptorType.ToCloseToken, DescriptorRecognition.StartsWith, false));
doesnt highlight the text between the {}
can anybody help me?
|
|
|
|
|
This is a bit of a hack but it gets it highlighting.
string cleanCurrentToken = curToken.Replace("\\{", "{");
switch (hd.DescriptorRecognition)
{
case DescriptorRecognition.WholeWord:
if (cleanCurrentToken == compareStr)
{
match = true;
}
break;
case DescriptorRecognition.StartsWith:
if (cleanCurrentToken.StartsWith(compareStr))
{
match = true;
}
break;
case DescriptorRecognition.Contains:
if (cleanCurrentToken.IndexOf(compareStr) != -1)
{
match = true;
}
break;
}
|
|
|
|
|
this does not work for me?
now it works
|
|
|
|
|
Hi,
Well done ! It's really great !
I had developed a simple text editor, but I didn't know how to color the words, so I selected them with RTB.Select(...) method and changed the selection color, but this was very stupid because makes the screen to flicker...
I just wanted to know how do you color the text, for example when a "/*" is entered ?
Thanks,
Ashkan S.
|
|
|
|
|
does string token support regex?
|
|
|
|
|
Thank you for sharing this great control with us!
|
|
|
|
|
OMG this is such an old article. But your source converts to .NET 3.5 without any problems.
Thank you so much
|
|
|
|
|
Thankyou very much .
Mark Brock
"We're definitely not going to make a G or a PG version of this. It's not PillowfightCraft." -- Chris Metzen
Click here to view my blog
|
|
|
|
|
Thanks for your job!
I want to set Tab Stops allowing to specify the intervals the cursor moves to when I press the tab key. But SelectionTabs property was auto cleared. Is it a bug?
|
|
|
|
|