简单记事本程序菜单设计
来源:互联网 发布:java程序员的自我修养 编辑:程序博客网 时间:2024/04/29 18:38
Form1.cs的里面的代码!
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 NotePadApp
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void 新建NToolStripMenuItem_Click(object sender, EventArgs e)
{
NoteForm note = new NoteForm();
note.MdiParent = this;
note.Show();
}
private void 退出XToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Close();
}
private void 关于AToolStripMenuItem_Click(object sender, EventArgs e)
{
MessageBox.Show("简单的记事本程序");
}
private void 打开OToolStripMenuItem_Click(object sender, EventArgs e)
{
string fileUrl = "";
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c://";
openFileDialog1.Filter = "txt files(*.txt)|*.txt|All files(*.*)|*.*";
openFileDialog1.RestoreDirectory = true;
if(openFileDialog1.ShowDialog()==DialogResult.OK)
{
fileUrl = openFileDialog1.FileName;
}
NoteForm note = new NoteForm();
note.MdiParent = this;
note.Show();
note.OpenFile(fileUrl);
}
private void 保存SToolStripMenuItem_Click(object sender, EventArgs e)
{
if(this.ActiveMdiChild != null)
{
NoteForm activeForm = (NoteForm)this.ActiveMdiChild;
activeForm.SaveFile();
}
}
private void 撤消UToolStripMenuItem_Click(object sender, EventArgs e)
{
if(this.ActiveMdiChild!=null)
{
NoteForm activeForm = (NoteForm)this.ActiveMdiChild;
activeForm.FrmUndo();
}
}
private void 重复RToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.ActiveMdiChild != null)
{
NoteForm activeForm = (NoteForm)this.ActiveMdiChild;
activeForm.FrmRedo();
}
}
private void 剪切TToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.ActiveMdiChild != null)
{
NoteForm activeForm = (NoteForm)this.ActiveMdiChild;
activeForm.FrmCut();
}
}
private void 复制CToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.ActiveMdiChild != null)
{
NoteForm activeForm = (NoteForm)this.ActiveMdiChild;
activeForm.FrmCopy();
}
}
private void 粘贴PToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.ActiveMdiChild != null)
{
NoteForm activeForm = (NoteForm)this.ActiveMdiChild;
activeForm.FrmPaste();
}
}
private void 全选AToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.ActiveMdiChild != null)
{
NoteForm activeForm = (NoteForm)this.ActiveMdiChild;
activeForm.FrmSelectAll();
}
}
}
}
再添加一个窗口!
相当于客户端!
命名为NotePadApp.cs
代码为
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;
namespace NotePadApp
{
public partial class NoteForm : Form
{
string fileName = "";
public NoteForm()
{
InitializeComponent();
this.WindowState = FormWindowState.Maximized;
}
public void OpenFile(string fileUrl)
{
fileName = fileUrl;
StringBuilder sb = new StringBuilder();
using (StreamReader sr = File.OpenText(fileUrl))
{
string input = "";
while ((input = sr.ReadLine()) != null)
{
sb.Append(input);
}
sr.Close();
}
this.richTextBox1.Text = sb.ToString();
}
public void SaveFile()
{
if(fileName =="")
{
if(this.saveFileDialog1.ShowDialog()==DialogResult.OK)
{
fileName = saveFileDialog1.FileName;
}
}
using (StreamWriter sw= new StreamWriter(fileName))
{
sw.Write(this.richTextBox1.Text);
}
}
public void FrmCopy()
{
this.richTextBox1.Copy();
}
public void FrmPaste()
{
this.richTextBox1.Paste();
}
public void FrmCut()
{
this.richTextBox1.Cut();
}
public void FrmSelectAll()
{
this.richTextBox1.SelectAll();
}
public void FrmUndo()
{
this.richTextBox1.Undo();
}
public void FrmRedo()
{
this.richTextBox1.Redo();
}
}
}
最后值得一提的是快速建立菜单项 在工具栏里拖MenuStrip到窗口上,然后在MenuStrip的右上角那个键选择
一个标准菜单集合!在通过编辑项把多余的给删除就行了!
- 简单记事本程序菜单设计
- 简单记事本程序
- 简单的记事本程序
- qml实现简单记事本程序
- 完成了简单记事本程序的编写
- 一个简单的记事本小程序源码
- 我写的简单记事本程序
- java实现的简单记事本程序
- 一个简单的java记事本程序
- 简单记事本程序java源码项目
- JAVA之记事本开发简单Java程序
- 记事本程序中字体菜单项界面出现错误
- 简单记事本
- 记事本程序
- 记事本程序
- 记事本程序
- javascript 简单导航菜单设计
- c语言--菜单设计程序
- ruby on rails 一步步开始(2)分页和简单查询
- 编译libjpeg库,jpeg-6b编译错误
- 翻译:测试成熟度模型集成(TMMi)(5)
- vista 下安装Apache server失败解决方案
- GlusterFS RAID1+RAID0方式的搭建(replicate与unify混用)
- 简单记事本程序菜单设计
- 教你写病毒
- Rails 数据库表之间关系
- GirdView 导出到Excel
- oracle简单对象类型
- s2sh整合配置文件信息
- 关于图形旋转的问题(GDI+)
- Ruby form的两种写法
- SiteMesh介绍