使用ICSharpCode.TextEditor.dll 做的一个代码高亮记事本
ICSharpCode.TextEditor来自开源项目SharpDevelop,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Gui.CompletionWindow;
using ICSharpCode.TextEditor.Document;
using ICSharpCode.TextEditor.Actions;
using System.Data.OleDb;
/*
<SyntaxModes version="1.0">
<Mode file = "ASPX.xshd"
name = "ASP3/XHTML"
extensions = ".asp"/>
<Mode file = "BAT-Mode.xshd"
name = "BAT"
extensions = ".bat"/>
<Mode file = "Boo.xshd"
name = "Boo"
extensions = ".boo"/>
<Mode file = "Coco-Mode.xshd"
name = "Coco"
extensions = ".atg"/>
<Mode file = "CPP-Mode.xshd"
name = "C++.NET"
extensions = ".c;.h;.cc;.C;.cpp;.hpp"/>
<Mode file = "CSharp-Mode.xshd"
name = "C#"
extensions = ".cs"/>
<Mode file = "HTML-Mode.xshd"
name = "HTML"
extensions = ".htm;.html"/>
<Mode file = "Java-Mode.xshd"
name = "Java"
extensions = ".java"/>
<Mode file = "JavaScript-Mode.xshd"
name = "JavaScript"
extensions = ".js"/>
<Mode file = "PHP-Mode.xshd"
name = "PHP"
extensions = ".php"/>
<Mode file = "Tex-Mode.xshd"
name = "TeX"
extensions = ".tex"/>
<Mode file = "VBNET-Mode.xshd"
name = "VBNET"
extensions = ".vb"/>
<Mode file = "XML-Mode.xshd"
name = "XML"
extensions = ".xml;.xsl;.xslt;.xsd;.manifest;.config;.addin;.xshd;.wxs;.proj;.csproj;
.vbproj;.ilproj;.booproj;.build;.xfrm;.targets;.xaml;.xpt;.xft"/>
</SyntaxModes>
*/
namespace CodeHelper
{
public partial class MainForm : Form
{
//此处声明了一个DataTable,用users表填充!后边会用到这个dt0
public DataTable dt0 = new DataTable("users");
//连接access数据库的连接字符串
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=CodeHelp.mdb";
//构造函数
public MainForm()
{
InitializeComponent();
}
private void cToolStripMenuItem_Click(object sender, EventArgs e)
{
textEditorControl1.Document.HighlightingStrategy = HighlightingStrategyFactory.
CreateHighlightingStrategy("ASP3/XHTML");
}
private void cNetToolStripMenuItem1_Click(object sender, EventArgs e)
{
//标记C#
textEditorControl1.Document.HighlightingStrategy =
HighlightingStrategyFactory.CreateHighlightingStrategy("C#");
cNetToolStripMenuItem1.Checked = true;
vBNetToolStripMenuItem.Checked = false;
cNetToolStripMenuItem.Checked = false;
xMLToolStripMenuItem.Checked = false;
texToolStripMenuItem.Checked = false;
pHPToolStripMenuItem.Checked = false;
javaScriptToolStripMenuItem.Checked = false;
javaToolStripMenuItem.Checked = false;
bATToolStripMenuItem.Checked = false;
coCoToolStripMenuItem.Checked = false;
hTMLToolStripMenuItem.Checked = false;
}
private void vBNetToolStripMenuItem_Click(object sender, EventArgs e)
{
//标记VBNET
textEditorControl1.Document.HighlightingStrategy =
HighlightingStrategyFactory.CreateHighlightingStrategy("VBNET");
cNetToolStripMenuItem1.Checked = false;
vBNetToolStripMenuItem.Checked = true;
cNetToolStripMenuItem.Checked = false;
xMLToolStripMenuItem.Checked = false;
texToolStripMenuItem.Checked = false;
pHPToolStripMenuItem.Checked = false;
javaScriptToolStripMenuItem.Checked = false;
javaToolStripMenuItem.Checked = false;
bATToolStripMenuItem.Checked = false;
coCoToolStripMenuItem.Checked = false;
hTMLToolStripMenuItem.Checked = false;
}
private void cNetToolStripMenuItem_Click(object sender, EventArgs e)
{
//标记C++NET
textEditorControl1.Document.HighlightingStrategy =
HighlightingStrategyFactory.CreateHighlightingStrategy("C++.NET");
cNetToolStripMenuItem1.Checked = false;
vBNetToolStripMenuItem.Checked = false;
cNetToolStripMenuItem.Checked = true;
xMLToolStripMenuItem.Checked = false;
texToolStripMenuItem.Checked = false;
pHPToolStripMenuItem.Checked = false;
javaScriptToolStripMenuItem.Checked = false;
javaToolStripMenuItem.Checked = false;
bATToolStripMenuItem.Checked = false;
coCoToolStripMenuItem.Checked = false;
hTMLToolStripMenuItem.Checked = false;
}
private void xMLToolStripMenuItem_Click(object sender, EventArgs e)
{
//标记XML
textEditorControl1.Document.HighlightingStrategy =
HighlightingStrategyFactory.CreateHighlightingStrategy("XML");
cNetToolStripMenuItem1.Checked = false;
vBNetToolStripMenuItem.Checked = false;
cNetToolStripMenuItem.Checked = false;
xMLToolStripMenuItem.Checked = true;
texToolStripMenuItem.Checked = false;
pHPToolStripMenuItem.Checked = false;
javaScriptToolStripMenuItem.Checked = false;
javaToolStripMenuItem.Checked = false;
bATToolStripMenuItem.Checked = false;
coCoToolStripMenuItem.Checked = false;
hTMLToolStripMenuItem.Checked = false;
}
private void iLAsmToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void texToolStripMenuItem_Click(object sender, EventArgs e)
{
//TEX标记
textEditorControl1.Document.HighlightingStrategy =
HighlightingStrategyFactory.CreateHighlightingStrategy("TeX");
cNetToolStripMenuItem1.Checked = false;
vBNetToolStripMenuItem.Checked = false;
cNetToolStripMenuItem.Checked = false;
xMLToolStripMenuItem.Checked = false;
texToolStripMenuItem.Checked = true;
pHPToolStripMenuItem.Checked = false;
javaScriptToolStripMenuItem.Checked = false;
javaToolStripMenuItem.Checked = false;
bATToolStripMenuItem.Checked = false;
coCoToolStripMenuItem.Checked = false;
hTMLToolStripMenuItem.Checked = false;
}
private void pHPToolStripMenuItem_Click(object sender, EventArgs e)
{
//php标记
textEditorControl1.Document.HighlightingStrategy =
HighlightingStrategyFactory.CreateHighlightingStrategy("PHP");
cNetToolStripMenuItem1.Checked = false;
vBNetToolStripMenuItem.Checked = false;
cNetToolStripMenuItem.Checked = false;
xMLToolStripMenuItem.Checked = false;
texToolStripMenuItem.Checked = false;
pHPToolStripMenuItem.Checked = true;
javaScriptToolStripMenuItem.Checked = false;
javaToolStripMenuItem.Checked = false;
bATToolStripMenuItem.Checked = false;
coCoToolStripMenuItem.Checked = false;
hTMLToolStripMenuItem.Checked = false;
}
private void javaScriptToolStripMenuItem_Click(object sender, EventArgs e)
{
//JAVASCRIPT标记
textEditorControl1.Document.HighlightingStrategy =
HighlightingStrategyFactory.CreateHighlightingStrategy("JavaScript");
cNetToolStripMenuItem1.Checked = false;
vBNetToolStripMenuItem.Checked = false;
cNetToolStripMenuItem.Checked = false;
xMLToolStripMenuItem.Checked = false;
texToolStripMenuItem.Checked = false;
pHPToolStripMenuItem.Checked = false;
javaScriptToolStripMenuItem.Checked = true;
javaToolStripMenuItem.Checked = false;
bATToolStripMenuItem.Checked = false;
coCoToolStripMenuItem.Checked = false;
hTMLToolStripMenuItem.Checked = false;
}
private void javaToolStripMenuItem_Click(object sender, EventArgs e)
{
//java标记
textEditorControl1.Document.HighlightingStrategy =
HighlightingStrategyFactory.CreateHighlightingStrategy("Java");
cNetToolStripMenuItem1.Checked = false;
vBNetToolStripMenuItem.Checked = false;
cNetToolStripMenuItem.Checked = false;
xMLToolStripMenuItem.Checked = false;
texToolStripMenuItem.Checked = false;
pHPToolStripMenuItem.Checked = false;
javaScriptToolStripMenuItem.Checked = false;
javaToolStripMenuItem.Checked = true;
bATToolStripMenuItem.Checked = false;
coCoToolStripMenuItem.Checked = false;
hTMLToolStripMenuItem.Checked = false;
}
private void bATToolStripMenuItem_Click(object sender, EventArgs e)
{
//BAT标记
textEditorControl1.Document.HighlightingStrategy =
HighlightingStrategyFactory.CreateHighlightingStrategy("BAT");
cNetToolStripMenuItem1.Checked = false;
vBNetToolStripMenuItem.Checked = false;
cNetToolStripMenuItem.Checked = false;
xMLToolStripMenuItem.Checked = false;
texToolStripMenuItem.Checked = false;
pHPToolStripMenuItem.Checked = false;
javaScriptToolStripMenuItem.Checked = false;
javaToolStripMenuItem.Checked = false;
bATToolStripMenuItem.Checked = true;
coCoToolStripMenuItem.Checked = false;
hTMLToolStripMenuItem.Checked = false;
}
private void coCoToolStripMenuItem_Click(object sender, EventArgs e)
{
//Coco标记
textEditorControl1.Document.HighlightingStrategy =
HighlightingStrategyFactory.CreateHighlightingStrategy("Coco");
cNetToolStripMenuItem1.Checked = false;
vBNetToolStripMenuItem.Checked = false;
cNetToolStripMenuItem.Checked = false;
xMLToolStripMenuItem.Checked = false;
texToolStripMenuItem.Checked = false;
pHPToolStripMenuItem.Checked = false;
javaScriptToolStripMenuItem.Checked = false;
javaToolStripMenuItem.Checked = false;
bATToolStripMenuItem.Checked = false;
coCoToolStripMenuItem.Checked = true;
hTMLToolStripMenuItem.Checked = false;
}
private void hTMLToolStripMenuItem_Click(object sender, EventArgs e)
{ //html标记
textEditorControl1.Document.HighlightingStrategy =
HighlightingStrategyFactory.CreateHighlightingStrategy("HTML");
cNetToolStripMenuItem1.Checked = false;
vBNetToolStripMenuItem.Checked = false;
cNetToolStripMenuItem.Checked = false;
xMLToolStripMenuItem.Checked = false;
texToolStripMenuItem.Checked = false;
pHPToolStripMenuItem.Checked = false;
javaScriptToolStripMenuItem.Checked = false;
javaToolStripMenuItem.Checked = false;
bATToolStripMenuItem.Checked = false;
coCoToolStripMenuItem.Checked = false;
hTMLToolStripMenuItem.Checked = true;
}
private void MainForm_Load(object sender, EventArgs e)
{
//标记C#
textEditorControl1.Document.HighlightingStrategy =
HighlightingStrategyFactory.CreateHighlightingStrategy("C#");
cNetToolStripMenuItem1.Checked = true;
vBNetToolStripMenuItem.Checked = false;
cNetToolStripMenuItem.Checked = false;
xMLToolStripMenuItem.Checked = false;
texToolStripMenuItem.Checked = false;
pHPToolStripMenuItem.Checked = false;
javaScriptToolStripMenuItem.Checked = false;
javaToolStripMenuItem.Checked = false;
bATToolStripMenuItem.Checked = false;
coCoToolStripMenuItem.Checked = false;
hTMLToolStripMenuItem.Checked = false;
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
原本要做一个 源代码管理器的,后来因为时间的关系 一直没有完成 期待时间充足的时候 继续写完