java textsharp,月光软件站 - 编程文档 - 其他语言 - 利用TextEditorControl控件现代码语法高亮显示...

/**********************************************************************************************

* 创建时间: 2005-1-19 16:32:06

* 作者:  Jack

*

* 介绍:  一个利用ICSharpCode.TextEditor.TextEditorControl控件

*    实现代码语法高亮显示的示例程序,需要引用ICSharpCode.TextEditor.dll文件

*    该文件可以在#develop的库中找到

**********************************************************************************************/

#region UsingBlock

using System;

using System.Drawing;

using System.Collections;

using System.ComponentModel;

using System.Windows.Forms;

using ICSharpCode.TextEditor;

using ICSharpCode.TextEditor.Gui.CompletionWindow;

using ICSharpCode.TextEditor.Document;

using ICSharpCode.TextEditor.Actions;

#endregion

namespace HighLightingCodeFile

{

///

/// ICSharpCode.TextEditor.

/// TextEditorControl的示例程序

///

public class TestCSharpTextBox : System.Windows.Forms.Form

{

#region 私有属性

private ICSharpCode.TextEditor.TextEditorControl textEditorControl;

private System.Windows.Forms.MainMenu mainMenu;

private System.Windows.Forms.MenuItem menuItem1;

private System.Windows.Forms.MenuItem OpenMenu;

private System.Windows.Forms.MenuItem Save;

private System.Windows.Forms.SaveFileDialog saveFileDialog;

private System.Windows.Forms.OpenFileDialog openFileDialog;

private System.Windows.Forms.MenuItem menuItem2;

private System.Windows.Forms.MenuItem menuItem3;

private System.Windows.Forms.MenuItem menuItem4;

private System.Windows.Forms.MenuItem menuItem5;

private System.Windows.Forms.MenuItem menuItem6;

private System.Windows.Forms.MenuItem menuItem7;

private System.Windows.Forms.MenuItem menuItem8;

#endregion

#region 属性

#endregion

#region 构造函数

public TestCSharpTextBox()

{

//

// Windows 窗体设计器支持所必需的

//

InitializeComponent();

textEditorControl.Document.HighlightingStrategy =

HighlightingStrategyFactory.CreateHighlightingStrategy("C#");

textEditorControl.Encoding = System.Text.Encoding.Default;

}

#endregion

#region 私有方法

#region Windows 窗体设计器生成的代码

///

/// 设计器支持所需的方法 - 不要使用代码编辑器修改

/// 此方法的内容。

///

private void InitializeComponent()

{

System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(TestCSharpTextBox));

this.textEditorControl = new ICSharpCode.TextEditor.TextEditorControl();

this.mainMenu = new System.Windows.Forms.MainMenu();

this.menuItem1 = new System.Windows.Forms.MenuItem();

this.OpenMenu = new System.Windows.Forms.MenuItem();

this.Save = new System.Windows.Forms.MenuItem();

this.menuItem2 = new System.Windows.Forms.MenuItem();

this.menuItem3 = new System.Windows.Forms.MenuItem();

this.menuItem4 = new System.Windows.Forms.MenuItem();

this.menuItem5 = new System.Windows.Forms.MenuItem();

this.menuItem6 = new System.Windows.Forms.MenuItem();

this.menuItem7 = new System.Windows.Forms.MenuItem();

this.menuItem8 = new System.Windows.Forms.MenuItem();

this.openFileDialog = new System.Windows.Forms.OpenFileDialog();

this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();

this.SuspendLayout();

//

// textEditorControl

//

this.textEditorControl.AutoScroll = true;

this.textEditorControl.Dock = System.Windows.Forms.DockStyle.Fill;

this.textEditorControl.Encoding = ((System.Text.Encoding)(resources.GetObject("textEditorControl.Encoding")));

this.textEditorControl.Location = new System.Drawing.Point(0, 0);

this.textEditorControl.Name = "textEditorControl";

this.textEditorControl.ShowEOLMarkers = true;

this.textEditorControl.ShowInvalidLines = false;

this.textEditorControl.ShowSpaces = true;

this.textEditorControl.ShowTabs = true;

this.textEditorControl.ShowVRuler = true;

this.textEditorControl.Size = new System.Drawing.Size(472, 454);

this.textEditorControl.TabIndex = 0;

//

// mainMenu

//

this.mainMenu.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

this.menuItem1,

this.menuItem2});

//

// menuItem1

//

this.menuItem1.Index = 0;

this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

this.OpenMenu,

this.Save});

this.menuItem1.Text = "File(&F)";

//

// OpenMenu

//

this.OpenMenu.Index = 0;

this.OpenMenu.Text = "&Open";

this.OpenMenu.Click += new System.EventHandler(this.OpenMenu_Click);

//

// Save

//

this.Save.Index = 1;

this.Save.Text = "&Save";

this.Save.Click += new System.EventHandler(this.Save_Click);

//

// menuItem2

//

this.menuItem2.Index = 1;

this.menuItem2.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {

this.menuItem3,

this.menuItem4,

this.menuItem5,

this.menuItem6,

this.menuItem7,

this.menuItem8});

this.menuItem2.Text = "CodeType(&T)";

//

// menuItem3

//

this.menuItem3.Index = 0;

this.menuItem3.Text = "&C#";

this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);

//

// menuItem4

//

this.menuItem4.Index = 1;

this.menuItem4.Text = "C++.&NET";

this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);

//

// menuItem5

//

this.menuItem5.Index = 2;

this.menuItem5.Text = "&Xml";

this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);

//

// menuItem6

//

this.menuItem6.Index = 3;

this.menuItem6.Text = "&Html";

this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);

//

// menuItem7

//

this.menuItem7.Index = 4;

this.menuItem7.Text = "&Java";

this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);

//

// menuItem8

//

this.menuItem8.Index = 5;

this.menuItem8.Text = "&VB.NET";

this.menuItem8.Click += new System.EventHandler(this.menuItem8_Click);

//

// TestCSharpTextBox

//

this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);

this.ClientSize = new System.Drawing.Size(472, 454);

this.Controls.Add(this.textEditorControl);

this.Menu = this.mainMenu;

this.Name = "TestCSharpTextBox";

this.Text = "TestCSharpTextBox";

this.ResumeLayout(false);

}

#endregion

#region 事件处理

private void OpenMenu_Click(object sender, System.EventArgs e)

{

OpenFileDialog oDia = new OpenFileDialog();

DialogResult result = oDia.ShowDialog();

if (result == DialogResult.OK)

{

textEditorControl.LoadFile(oDia.FileName);

}

}

private void menuItem3_Click(object sender, System.EventArgs e)

{

textEditorControl.Document.HighlightingStrategy =

HighlightingStrategyFactory.CreateHighlightingStrategy("C#");

}

private void menuItem4_Click(object sender, System.EventArgs e)

{

textEditorControl.Document.HighlightingStrategy =

HighlightingStrategyFactory.CreateHighlightingStrategy("C++.NET");

}

private void menuItem5_Click(object sender, System.EventArgs e)

{

textEditorControl.Document.HighlightingStrategy =

HighlightingStrategyFactory.CreateHighlightingStrategy("XML");

}

private void menuItem6_Click(object sender, System.EventArgs e)

{

textEditorControl.Document.HighlightingStrategy =

HighlightingStrategyFactory.CreateHighlightingStrategy("HTML");

}

private void menuItem7_Click(object sender, System.EventArgs e)

{

textEditorControl.Document.HighlightingStrategy =

HighlightingStrategyFactory.CreateHighlightingStrategy("Java");

}

private void menuItem8_Click(object sender, System.EventArgs e)

{

textEditorControl.Document.HighlightingStrategy =

HighlightingStrategyFactory.CreateHighlightingStrategy("VBNET");

}

private void Save_Click(object sender, System.EventArgs e)

{

SaveFileDialog sDia = new SaveFileDialog();

DialogResult result = sDia.ShowDialog();

if (result == DialogResult.OK)

{

textEditorControl.SaveFile(sDia.FileName);

}

}

#endregion

#endregion

#region 入口点

[STAThread]

static void Main()

{

Application.Run(new TestCSharpTextBox());

}

#endregion

#region 公有方法

#endregion

}

}

down_info.asp?id=42106

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值