Hi Guys,
How to attach richTextBox object to ICSharpCode.TextEditor library?? I couldn't find any code for this purpose. Any help appreciated.
Thanks in advance.
Hi Guys,
How to attach richTextBox object to ICSharpCode.TextEditor library?? I couldn't find any code for this purpose. Any help appreciated.
Thanks in advance.
Add reference to ICSharpcode.TextEditor to your project
Add following class
public class AppSyntaxModeProvider : ISyntaxModeFileProvider
{
List< syntaxmode > syntaxModes = null;
public ICollection< syntaxmode > SyntaxModes {
get {
return syntaxModes;
}
}
public AppSyntaxModeProvider()
{
Assembly assembly = Assembly.GetExecutingAssembly();
//enumerate resource names if need
//foreach (string resourceName in assembly.GetManifestResourceNames()){}
//load modes list
Stream syntaxModeStream = assembly.GetManifestResourceStream("WindowsFormsApplication1.Resources.SyntaxModes.xml");
if (syntaxModeStream != null) {
syntaxModes = SyntaxMode.GetSyntaxModes(syntaxModeStream);
} else {
syntaxModes = new List< syntaxmode >();
}
}
public XmlTextReader GetSyntaxModeFile(SyntaxMode syntaxMode)
{
Assembly assembly = Assembly.GetExecutingAssembly();
// load syntax schema
Stream stream = assembly.GetManifestResourceStream("WindowsFormsApplication1.Resources." + syntaxMode.FileName);
return new XmlTextReader(stream);
}
public void UpdateSyntaxModeList()
{
// resources don't change during runtime
}
}
Add schema files to embedded resources
Attach schema provider to control
// Attach to the text editor.
HighlightingManager.Manager.AddSyntaxModeFileProvider(
new AppSyntaxModeProvider());
Set current syntax scheme to control
editor.SetHighlighting("SQL");
Sample code can be downloaded from detailed blog article
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.