一个WinForm记事本程序(包含主/下拉/弹出菜单/打开文件/保存文件/打印/页面设置/字体/颜色对话框/剪切版操作等等控件用法以及记事本菜单事件/按键事件的具体代码)

这是一个使用C#编写的WinForm应用程序,模仿了Windows记事本的功能,包括新建、打开、保存、打印、页面设置、字体和颜色选择等操作。代码详细展示了如何实现菜单事件和键盘事件,以及使用各种对话框进行文件操作。
摘要由CSDN通过智能技术生成

(一).说明

        功能类似Windows 操作系统自带的记事本.  一个WinForm记事本程序(包含主/下拉/弹出

        菜单/打开保存对话框等控件用法以及记事本菜单事件的具体代码)

(二).图片示例

(三).代码

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Printing;
using System.Data;

namespace 记事本
{
 /// <summary>
 /// Form1 的摘要说明。
 /// </summary>
 public class FormMain : System.Windows.Forms.Form
 {
  private System.Windows.Forms.TextBox textBoxEdit;
  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private System.ComponentModel.Container components = null;
  private System.Windows.Forms.MainMenu mainMenu1;
  private System.Windows.Forms.MenuItem menuItem8;
  private System.Windows.Forms.MenuItem menuItem11;
  private System.Windows.Forms.MenuItem menuItem14;
  private System.Windows.Forms.MenuItem menuItem19;
  private System.Windows.Forms.MenuItem menuItem22;
  private System.Windows.Forms.MenuItem menuItemFile;
  private System.Windows.Forms.MenuItem menuItemEdit;
  private System.Windows.Forms.MenuItem menuItemFormat;
  private System.Windows.Forms.MenuItem menuItemNew;
  private System.Windows.Forms.MenuItem menuItemOpen;
  private System.Windows.Forms.MenuItem menuItemSave;
  private System.Windows.Forms.MenuItem menuItemSaveAs;
  private System.Windows.Forms.MenuItem menuItemPageSet;
  private System.Windows.Forms.MenuItem menuItemPrint;
  private System.Windows.Forms.MenuItem menuItemExit;
  private System.Windows.Forms.MenuItem menuItemUndo;
  private System.Windows.Forms.MenuItem menuItemCut;
  private System.Windows.Forms.MenuItem menuItemCopy;
  private System.Windows.Forms.MenuItem menuItemPaste;
  private System.Windows.Forms.MenuItem menuItemDel;
  private System.Windows.Forms.MenuItem menuItemSelAll;
  private System.Windows.Forms.MenuItem menuItemWordWrap;
  private System.Windows.Forms.MenuItem menuItemFont;
  private System.Windows.Forms.MenuItem menuItemColor;
  const int MaxLenght=2000000;
       
  private string currentFileName;
  private System.Drawing.Printing.PrintDocument printDocument=new PrintDocument();
  private bool needToSave;
  public FormMain()
  {
   //
   // 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.textBoxEdit = new System.Windows.Forms.TextBox();
   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.menuItemPageSet = new System.Windows.Forms.MenuItem();
   this.menuItemPrint = new System.Windows.Forms.MenuItem();
   this.menuItem11 = new System.Windows.Forms.MenuItem();
   this.menuItemExit = new System.Windows.Forms.MenuItem();
   this.menuItemEdit = new System.Windows.Forms.MenuItem();
   this.menuItemUndo = new System.Windows.Forms.MenuItem();
   this.menuItem14 = new System.Windows.Forms.MenuItem();
   this.menuItemCut = new System.Windows.Forms.MenuItem();
   this.menuItemCopy = new System.Windows.Forms.MenuItem();
   this.menuItemPaste = new System.Windows.Forms.MenuItem();
   this.menuItemDel = new System.Windows.Forms.MenuItem();
   this.menuItem19 = new System.Windows.Forms.MenuItem();
   this.menuItemSelAll = new System.Windows.Forms.MenuItem();
   this.menuItemFormat = new System.Windows.Forms.MenuItem();
   this.menuItemWordWrap = new System.Wind

  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 13
    评论
评论 13
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值