我写的一段"记事本"的程序,请高手指教.

原创 2002年07月16日 14:28:00

不知C#是不是这么用的,我写的有没有体现C#的OOP思想.
程序没有写完,也很不完善,只是请各位指点一下.谢谢!!
____________________________________________________
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;

namespace notePad
{
 /// <summary>
 /// Form1 的摘要说明。
 /// </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 menuItemAbout;
        private System.Windows.Forms.ToolBar toolBarOnly;
        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 窗体设计器支持所必需的
   //
   InitializeComponent();

   //
   // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
   //
  }

  /// <summary>
  /// 清理所有正在使用的资源。
  /// </summary>
  protected override void Dispose( bool disposing )
  {
   if( disposing )
   {
    if (components != null)
    {
     components.Dispose();
    }
   }
   base.Dispose( disposing );
  }

  #region Windows Form Designer generated code
  /// <summary>
  /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  /// 此方法的内容。
  /// </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.menuItemEdit = 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;
            //
            // mainMenu1
            //
            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.menuItemPrint.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 = "&About";
            //
            // 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_Tick);
            //
            // 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();
            ((System.ComponentModel.ISupportInitialize)(this.statusBarPanelFileName)).EndInit();
            this.ResumeLayout(false);

        }
  #endregion

  /// <summary>
  /// 应用程序的主入口点。
  /// </summary>
  [STAThread]
  static void Main()
  {
   Application.Run(new notePad());
  }

        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 = "文本文件 (*.txt)|*.txt|所有文件 (*.*)|*.*";
            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 = "文本文件 (*.txt)|*.txt|所有文件 (*.*)|*.*";
            saveFileDialog1.ShowDialog();
            if(saveFileDialog1.FileName.Length > 0)
            {
                richTextBox1.SaveFile(saveFileDialog1.FileName,RichTextBoxStreamType.PlainText);
                statusBarPanelFileName.Text = saveFileDialog1.FileName;
            }
        }

        private void notePad_Closing(object sender, System.ComponentModel.CancelEventArgs e)
        {
            if(oemText != richTextBox1.Text)
            {
                DialogResult msgReturn;
                msgReturn = MessageBox.Show("The text already changed , Are you saved change .","Exit",MessageBoxButtons.YesNoCancel,MessageBoxIcon.Question);
                switch (msgReturn)
                {
                    case DialogResult.Yes:
                        menuItemSaveAs_Click(this,null);
                        break;
                    case DialogResult.No:
                        //do nothing;
                        return;
                }
            }
        }
    }
}

请高手指教

'========================================================= ' Program:ShyPost??? ' Version:? ' Dat...
  • dishuabo1172
  • dishuabo1172
  • 2017年01月02日 13:51
  • 116

请高手指教!

现有表ABC,数据如下:DATA                 NAME              SIZE                                QUANTITY     ...
  • phuaye2005
  • phuaye2005
  • 2005年12月01日 14:18
  • 261

请高手来指教

     我们知道硬件是基础,软件是灵魂。操作系统是核心,一切软件都是架构在操作系统之上,编译器更是提供给人们发挥想象空间的利器。     我们学习程序设计应该学最核心的东西:数据结构和算法。的确,设...
  • HERO_1
  • HERO_1
  • 2009年05月15日 18:30
  • 293

Java小程序之我的记事本

Java小程序之我的记事本 前言:Java中的流的知识非常重要,刚开始学,一定要多花时间对流的分类以及继承的知识学明白,只有这样,对流的应用才会了然于胸; 好了,言归正传,今天给大家写一个利用...
  • BlueSky_USC
  • BlueSky_USC
  • 2016年11月27日 00:25
  • 1401

请高手指教!谢谢!

大家好,请高手指教指教!我已经在学校里面呆了快两年了,专业是软件技术,但是我好象什么都没有学到,对于软件理论是可以的,但是说到亲手去做,我觉得很困难。请问各位高手有什么好的学习方法让我的能力更加提高吗...
  • kyodunlps
  • kyodunlps
  • 2007年03月17日 09:22
  • 259

请高手指教。

小弟想入门DELPHI 请问从那里入手比较好。
  • pjackycool
  • pjackycool
  • 2004年08月01日 19:31
  • 109

用记事本开发C#程序

一般做.NET开发,我们都是用集成开发环境VS。实际上和java一样,我们也是可以直接使用记事本等任何文本编辑工具进行C#的开发。下面简述一下如何用技术本编写C#程序。 1、首先电脑上必须有.NET...
  • thebestleo
  • thebestleo
  • 2016年09月09日 16:07
  • 1349

一段费解的程序,请高手解答:)

 using System;using System.Collections.Generic;using System.Text;using System.IO;namespace ConsoleAp...
  • thebesghost
  • thebesghost
  • 2006年09月18日 19:04
  • 678

新人请多指教,自我介绍

自我介绍,新人请多指教
  • wh01096045
  • wh01096045
  • 2015年09月03日 21:29
  • 171

用记事本写一个简单的java程序

用记事本写一个简单的java程序第一步: 安装好jdk,并设置好环境变量。 桌面-计算机(右键)-属性-高级系统设置-环境变量-path-在变量值后加上;和jdk安装路径加...
  • lxh_gdmu
  • lxh_gdmu
  • 2015年07月21日 03:59
  • 668
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:我写的一段"记事本"的程序,请高手指教.
举报原因:
原因补充:

(最多只允许输入30个字)