I do not know C # is not so used, I have to write C # does not reflect the thinking of OOP program is not finished, but also far from perfect, but please gets advice Thank you !! ____________________________________________________ using System;.. Using System.Drawing; using System.Collections Using system.componentmodel; use system.windows.forms; using system.data; using system.io;
A summary description of Namespace NotePad {///
/// summary> public class notePad: System.Windows.Forms.Form {private System.Windows.Forms.RichTextBox richTextBox1; private System.Windows.Forms.MainMenu mainMenu1; private System.Windows.Forms.MenuItem menuItem8; private System.Windows.Forms.MenuItem menuItem10; private System.Windows.Forms.MenuItem menuItemFile; private System.Windows.Forms.MenuItem menuItemEdit; private System.Windows.Forms.MenuItem menuItemOption; private System.Windows.Forms.MenuItem menuItemHelp; private System.Windows.Forms.MenuItem menuItemNew; private System.Windows.Forms.MenuItem menuItemOpen; private System.Windows.Forms.MenuItem menuItemPrint; private System.Windows.Forms.MenuItem menuItemExit; private System.Windows.Forms.MenuItem menuItemFont; private System.windows.Forms.Menuitem MenuItemwordWRAP; Private System.Windows.Forms.Menuitem MenuItemWorm / Private System.Windows.Forms.toolbar Too lBarOnly; private System.Windows.Forms.ToolBarButton toolBarButtonNew; private System.Windows.Forms.ToolBarButton toolBarButtonOpen; private System.Windows.Forms.StatusBar statusBarOnly; private System.Windows.Forms.StatusBarPanel statusBarPanelTime; private System.Windows.Forms.OpenFileDialog openFileDialog1; private System.Windows.Forms.ImageList imageList1; private System.Windows.Forms.FontDialog fontDialog1; private System.Windows.Forms.Timer timer1; private System.ComponentModel.IContainer components; private System.Windows.Forms.SaveFileDialog saveFileDialog1; Private system.windows.Forms.MenuItem MenuItemsave;
private System.Windows.Forms.MenuItem menuItemSaveAs; private System.Windows.Forms.StatusBarPanel statusBarPanelFileName; private string oemText = ""; public notePad () {// // Windows Forms designer support necessary // InitializeComponent () ;
// // Todo: Add any constructor code after INITIALIZEComponent call //}
///
#Region Windows Form Designer Generated Code ///
/// summary> private void InitializeComponent () {this.components = new System.ComponentModel.Container (); System.Resources.ResourceManager resources = new System.Resources.ResourceManager (typeof (notePad)); this.richTextBox1 = new System.Windows.Forms.RichTextBox (); this.mainMenu1 = new System.Windows.Forms.MainMenu (); this.menuItemFile = new System.Windows.Forms.MenuItem (); this.menuItemNew = new System.Windows. Forms.MenuItem (); this.menuItemOpen = new System.Windows.Forms.MenuItem (); this.menuItemSave = new System.Windows.Forms.MenuItem (); this.menuItemSaveAs = new System.Windows.Forms.MenuItem () ; this.menuItem8 = new System.Windows.Forms.MenuItem (); this.menuItemPrint = new System.Windows.Forms.MenuItem (); this.menuItem10 = new System.Windows.Forms.MenuItem (); this.menuItemExit = New system.windows.Forms.MenuItem (); this.Menuit emEdit = new System.Windows.Forms.MenuItem (); this.menuItemOption = new System.Windows.Forms.MenuItem (); this.menuItemFont = new System.Windows.Forms.MenuItem (); this.menuItemWordWrap = new System. Windows.Forms.MenuItem (); this.menuItemHelp = new System.Windows.Forms.MenuItem (); this.menuItemAbout = new System.Windows.Forms.MenuItem (); this.toolBarOnly = new System.Windows.Forms.ToolBar (); This.toolbarbuttonnew = new system.windows.Forms.toolbarButton (); this.toolbarbuttonopen = new system.windows.forms.toolbarbutton (); this.imagelist1 =
new System.Windows.Forms.ImageList (this.components); this.statusBarOnly = new System.Windows.Forms.StatusBar (); this.statusBarPanelTime = new System.Windows.Forms.StatusBarPanel (); this.statusBarPanelFileName = new System .Windows.Forms.StatusBarPanel (); this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog (); this.fontDialog1 = new System.Windows.Forms.FontDialog (); this.timer1 = new System.Windows.Forms. Timer (this.components); this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog (); ((System.ComponentModel.ISupportInitialize) (this.statusBarPanelTime)) BeginInit ();. ((System.ComponentModel.ISupportInitialize) ( . this.statusBarPanelFileName)) BeginInit (); this.SuspendLayout (); // // richTextBox1 // this.richTextBox1.AutoWordSelection = true; this.richTextBox1.Location = new System.Drawing.Point (1, 30); this.richTextBox1.Name = "richTextBox1"; this.richTextBox1.ScrollBars = System.Windows.Forms.RichTextBoxScrollBars.ForcedBoth; this.richTextBox1.Size = new System.Drawing.Size (556, 298); this.richTextBox1.TabIndex = 0; this.RichtextBox1.text = ""; this.richtextbox1.wordwrap = false;
////Minmenu1 // this.mainMenu1.Menuitems.addrange (new system.windows.Forms.Menuitem [] {this.Menuitemfile, this.MenuiteMedit, this.Menuitemoption, this.MenuiteMhelp}; //// MenuItemFile / / This.Menuitemfile.index = 0; this.Menuitemfile.Menuitems.addrange (new system.windows.forms.Menuitem [] {this.MenuItemNew, this.Menuitemopen, This.MenuItemsave, this.menuitemsaveas, this.menuitem8, this.menuitemprint, this.menuitem10, this.MenuiteMexit}; this.MenuItemFile.Text = "& file";
// //Menuitemnew // this.Menuitemnew.index = 0; this.Menuitemnew.text = "& new"; // // Menuitemopen // this.MenuItemOpen.index = 1; this.Menuitemopen.Text = "& open"; this.menuItemOpen.Click = new System.EventHandler (this.menuItemOpen_Click); // // menuItemSave // this.menuItemSave.Index = 2; this.menuItemSave.Text = "& Save"; // // menuItemSaveAs // this .menuItemSaveAs.Index = 3; this.menuItemSaveAs.Text = "Save & As ..."; this.menuItemSaveAs.Click = new System.EventHandler (this.menuItemSaveAs_Click); // // menuItem8 // this.menuItem8.Index = 4; this.Menuitem8.Text = "-"; // // MenuiteMprint // this.MenuItemprint.index = 5; this.MenuiteMpri nt.text = "& print"; // // Menuitem10 // this.Menuitem10.index = 6; this.Menuitem10.Text = "-"; /// MenuiteMexit // this.MenuiteMexit.index = 7; this. menuItemExit.Text = "E & xit"; this.menuItemExit.Click = new System.EventHandler (this.menuItemExit_Click); // // menuItemEdit // this.menuItemEdit.Index = 1; this.menuItemEdit.Text = "& Edit";
// // menuItemOption // this.menuItemOption.Index = 2; this.menuItemOption.MenuItems.AddRange (new System.Windows.Forms.MenuItem [] {this.menuItemFont, this.menuItemWordWrap}); this.menuItemOption.Text = "& Option"; // // Menuitemfont // this.Menuitemfont.index = 0; this.Menuitemfont.text = "& font"; this.Menuitemfont.Click = new system.eventhandler (this.MenuItemFont_Click); // // menuItemWordWrap // this.menuItemWordWrap.Index = 1; this.menuItemWordWrap.Text = "& WordWrap"; this.menuItemWordWrap.Click = new System.EventHandler (this.menuItemWordWrap_Click); // // menuItemHelp // This.MenuiteMhelp.index = 3; this.Menuitemhelp.Menuitems.addrange (new system.windows.Forms.Menuitem [] {this.MenuItemAbout}); this.MenuiteMhelp.text = "& help"; /// MenuiteMabout // This.Menuitemabout.index = 0; this.Menuitemabout.text = "& quide";
// // toolBarOnly // this.toolBarOnly.Buttons.AddRange (new System.Windows.Forms.ToolBarButton [] {this.toolBarButtonNew, this.toolBarButtonOpen}); this.toolBarOnly.ButtonSize = new System.Drawing.Size (24 , 24); this.toolBarOnly.DropDownArrows = true; this.toolBarOnly.ImageList = this.imageList1; this.toolBarOnly.Name = "toolBarOnly"; this.toolBarOnly.ShowToolTips = true; this.toolBarOnly.Size = new System.Drawing .Size (560, 27); this.toolBarOnly.TabIndex = 1; this.toolBarOnly.ButtonClick = new System.Windows.Forms.ToolBarButtonClickEventHandler (this.toolBarOnly_ButtonClick); this.toolBarOnly.MouseEnter = new System.EventHandler (this .toolbaronly_mouseenter; // // toolBarButtonNew // this.toolBarButtonNew.ImageIndex = 0; this.toolBarButtonNew.Text = "New"; this.toolBarButtonNew.ToolTipText = "Creat a New text"; // // toolBarButtonOpen // this.toolBarButtonOpen.ImageIndex = 2 ; this.toolBarButtonOpen.Text = "Open"; this.toolBarButtonOpen.ToolTipText = "Open a text"; // // imageList1 // this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit; this.imageList1. Imagesize =
new System.Drawing.Size (16, 16); this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer) (resources.GetObject ( "imageList1.ImageStream"))); this.imageList1.TransparentColor = System. Drawing.Color.Transparent; // // statusBarOnly // this.statusBarOnly.AllowDrop = true; this.statusBarOnly.Location = new System.Drawing.Point (0, 324); this.statusBarOnly.Name = "statusBarOnly"; this .statusBarOnly.Panels.AddRange (new System.Windows.Forms.StatusBarPanel [] {this.statusBarPanelTime, this.statusBarPanelFileName}); this.statusBarOnly.ShowPanels = true; this.statusBarOnly.Size = new System.Drawing.Size (560 , 13); this.statusbaronly.tabindex = 2; // // statusBarPanelTime // this.statusBarPanelTime.BorderStyle = System.Windows.Forms.StatusBarPanelBorderStyle.None; this.statusBarPanelTime.Width = 50; // // statusBarPanelFileName // this.statusBarPanelFileName.Text = "Need a name"; this. StatusbarPanelFileName.Width = 200; // // Timer1 // this.timer1.enabled = true; this.timer1.interval = 1000; this.timer1.tick = new system.EventHandler (this.timer1_thing);
//// savefiledialog1 // this.savefiledialog1.filename = "doc1"; //// Notepad // this.autoscalebasesize = new system.drawing.size (6, 14); this.clientsize = new system.drawing.size (560, 337); this.controls.addrange (new system.windows.forms.control [] {this.statusbaronly, this.toolbaronly, this.richtextbox1}); this.Menu = this.mainMenu1; this.name = " notePad "; this.Text =" My NotePad "; this.Closing = new System.ComponentModel.CancelEventHandler (this.notePad_Closing); this.SizeChanged = new System.EventHandler (this.notePad_SizeChanged); ((System.ComponentModel. ISupportInitialize) (this.statusbarpaneltime))) .Endinit (); (this.statusbarpanelfilename). Endinit (); this.ResumeLayout (false);} #ENDREGION
///
Private void notepad_sizechanged (object sender, system.eventargs e) {richtextbox1.width = this.width - 12; richtextbox1.height = this.Height - 100;
private void menuItemWordWrap_Click (object sender, System.EventArgs e) {if (menuItemWordWrap.Checked == true) {richTextBox1.WordWrap = false; menuItemWordWrap.Checked = false;} else {richTextBox1.WordWrap = true; menuItemWordWrap.Checked = true; }}} Private void menuItemOpen_Click (Object sender, system.eventargs e) {OpenFiledialog1.filter = "text file (* .txt) | * .txt | All files (*. *) | *. *"; Openfiledialog1.showdialog () ; if (openFileDialog1.FileName.Length> 0) {StreamReader fileReader = new StreamReader (openFileDialog1.FileName, System.Text.Encoding.GetEncoding ( "gb2312")); richTextBox1.Text = fileReader.ReadToEnd (); oemText = fileReader. ReadToend (); StatusBarPanelFileName.Text = OpenFiledialog1.FileName; FileReader.close (); }
private void toolBarOnly_ButtonClick (object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) {switch (toolBarOnly.Buttons.IndexOf (e.Button)) {case 0: // break; case 1: this.menuItemOpen_Click (this, null); break;}} private void menuItemFont_Click (object sender, System.EventArgs e) {fontDialog1.ShowDialog (); richTextBox1.Font = fontDialog1.Font;} private void timer1_Tick (object sender, System.EventArgs e) {statusBarPanelTime.Text = DateTime .Now.ToString ( "hh: mm: ss");} private void toolBarOnly_MouseEnter (object sender, System.EventArgs e) {// toolBarOnly.Buttons.IndexOf} private void menuItemExit_Click (object sender, System.EventArgs e) {. THIS.CLOSE ();
Private void MenuiteMsaveas_Click (Object sender, system.eventargs e) {savefiledialog1.filter = text file (* .txt) | * .txt | All files (*. *) | *. * "; SaveFileDialog1.showdialog (); if (saveFileDialog1.FileName.Length> 0) {richTextBox1.SaveFile (saveFileDialog1.FileName, RichTextBoxStreamType.PlainText); statusBarPanelFileName.Text = saveFileDialog1.FileName;}}