为了正常的体验网站,请在浏览器设置里面开启Javascript功能!

记事本 程序源代码

2012-02-12 5页 doc 55KB 63阅读

用户头像

is_739838

暂无简介

举报
记事本 程序源代码程序源代码: Form1: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Drawing.Printing; namespac...
记事本 程序源代码
程序源代码: Form1: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Drawing.Printing; namespace 记事本1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void 新建ToolStripMenuItem_Click(object sender, EventArgs e) { this.Text = "无标题-记事本"; richTextBox1.Text = ""; } private void 打开ToolStripMenuItem_Click(object sender, EventArgs e) { openFileDialog1.FileName = ""; openFileDialog1.Filter = "RTF File(*.rtf)|*.RTF|TXT FILE(*.txt)|*.txt"; openFileDialog1.ShowDialog(); if (openFileDialog1.FileName != "") switch (openFileDialog1.FilterIndex) { case 1: richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.RichText); break; case 2: richTextBox1.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText); break; } } private void 保存ToolStripMenuItem_Click(object sender, EventArgs e) { saveFileDialog1.Filter = "RTF File(*.rtf)|*.RTF|TXT FILE(*.txt)|*.txt"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) switch (openFileDialog1.FilterIndex) { case 1: richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.RichText); break; case 2: richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText); break; } } private void 另存为ToolStripMenuItem_Click(object sender, EventArgs e) { saveFileDialog1.Filter = "RTF File(*.rtf)|*.RTF|TXT FILE(*.txt)|*.txt"; if (saveFileDialog1.ShowDialog() == DialogResult.OK) switch (openFileDialog1.FilterIndex) { case 1: richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.RichText); break; case 2: richTextBox1.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText); break; } } private void 退出ToolStripMenuItem_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("确定退出吗?", "记事本", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation); if (result == DialogResult.Yes) { Application.Exit(); } } private void 剪切AToolStripMenuItem_Click(object sender, EventArgs e) { richTextBox1.Cut(); } private void 复制BToolStripMenuItem_Click(object sender, EventArgs e) { richTextBox1.Copy(); } private void 粘贴CToolStripMenuItem_Click(object sender, EventArgs e) { richTextBox1.Paste(); } private void 删除DToolStripMenuItem_Click(object sender, EventArgs e) { if (richTextBox1.SelectedText != "") richTextBox1.SelectedText = ""; } private void 撤销ToolStripMenuItem_Click(object sender, EventArgs e) { richTextBox1.Undo(); } private void 全选AToolStripMenuItem_Click(object sender, EventArgs e) { richTextBox1.SelectAll(); } private void 颜色ToolStripMenuItem_Click(object sender, EventArgs e) { colorDialog1.AllowFullOpen = true; colorDialog1.AnyColor = true; colorDialog1.SolidColorOnly = false; if (colorDialog1.ShowDialog() == DialogResult.OK) { if (richTextBox1.SelectedText == "") richTextBox1.SelectAll(); richTextBox1.SelectionColor = colorDialog1.Color; } } private void 字体ToolStripMenuItem_Click(object sender, EventArgs e) { fontDialog1.AllowVectorFonts = true; fontDialog1.AllowVerticalFonts = true; fontDialog1.FixedPitchOnly = false; fontDialog1.MaxSize = 72; fontDialog1.MinSize = 5; if (fontDialog1.ShowDialog() == DialogResult.OK) { if (richTextBox1.SelectedText == "") richTextBox1.SelectAll(); richTextBox1.SelectionFont = fontDialog1.Font; } } private void 状态栏ToolStripMenuItem_Click(object sender, EventArgs e) { if (this.状态栏ToolStripMenuItem.Checked == false) { this.状态栏ToolStripMenuItem.Checked = true; this.statusStrip1.Visible = true; this.richTextBox1.Height -= 22; } else { this.状态栏ToolStripMenuItem.Checked = false; this.statusStrip1.Visible = false; this.richTextBox1.Height += 22; } } private void richTextBox1_TextChanged(object sender, EventArgs e) { int row = richTextBox1.GetLineFromCharIndex(richTextBox1.SelectionStart) + 1; int start = richTextBox1.GetFirstCharIndexOfCurrentLine(); string s = richTextBox1.Text.Substring(start, richTextBox1.SelectionStart - start); int col = GetStringLen(s) + 1; toolStripStatusLabel1.Text = "第 " + row + " 行, 第 " + col + " 列"; } private int GetStringLen(string s) { if (!string.IsNullOrEmpty(s)) { int len = s.Length; for (int i = 0; i < s.Length; i++) { if (s[i] > 255) len++; } return len; } return 0; } private void 自动换行ToolStripMenuItem_Click(object sender, EventArgs e) { if (this.自动换行ToolStripMenuItem.Checked == false) { this.自动换行ToolStripMenuItem.Checked = true; this.richTextBox1.WordWrap = true; } else { this.自动换行ToolStripMenuItem.Checked = false; this.richTextBox1.WordWrap = false; } } private void 关于记事本AToolStripMenuItem_Click(object sender, EventArgs e) { Form2 About = new Form2(); About.Show(); } } } Form 2: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace 记事本1 { public partial class Form2 : Form { public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { this.Close(); } } }
/
本文档为【记事本 程序源代码】,请使用软件OFFICE或WPS软件打开。作品中的文字与图均可以修改和编辑, 图片更改请在作品中右键图片并更换,文字修改请直接点击文字进行修改,也可以新增和删除文档中的内容。
[版权声明] 本站所有资料为用户分享产生,若发现您的权利被侵害,请联系客服邮件isharekefu@iask.cn,我们尽快处理。 本作品所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用。 网站提供的党政主题相关内容(国旗、国徽、党徽..)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。

历史搜索

    清空历史搜索