/ ************************************************** ******************************************* * Creation time: 2005 -1-19 16:32:06 * author: Jack * * description: * implement a use ICSharpCode.TextEditor.TextEditorControl control sample program code syntax highlighting, need to reference ICSharpCode.TextEditor.dll file * the file can be # Database for Delin, ***************************************************************************** ********************************************************* /
#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;
#ndregion
namespace HighLightingCodeFile {///
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 attribute constructors public #endregion #region TestCSharpTextBox () {// // // InitializeComponent Windows form Designer supports required (); textEditorControl.Document.HighlightingStrategy = HighlightingStrategyFactory.CreateHighlightingStrategy ( "C #"); TextEditorControl.Encoding = system.text.Encoding.default;} #endregion #Region Private method #Region Windows Form Designer Generated code ///
/// summary> 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.SuspendLa yout (); // // 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, THI S.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);
/////////////Uitem5.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); //////uitem8 // 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
#REGON event handling
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
#ndregion
#Region entry point
[Stathread] static void main () {Application.run (new testcsharptextbox ());
#endregion #Region public method #ENDREGON}}