简单记事本程序菜单设计
2010-04-30 10:55
381 查看
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的右上角那个键选择
一个标准菜单集合!在通过编辑项把多余的给删除就行了!
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的右上角那个键选择
一个标准菜单集合!在通过编辑项把多余的给删除就行了!
相关文章推荐
- Visual C# 2008+SQL Server 2005 数据库与网络开发--13.1.3 简单记事本程序菜单设计
- C++考试小程序编程思路和简单设计
- 我想写程序#3 之 「简单地设计自己的数据表(Table)」
- 一个简单的实现不同权限的用户登录后看到不同的菜单设计的数据库表清单
- ※回顾※简单的事情也要做好,嵌入式程序设计技巧的掌握之一
- Python设计模式编程中解释器模式的简单程序示例分享
- 八条设计多线程程序的简单规则
- C#串口介绍以及简单串口通信程序设计实现
- 简单设计并开发一个移动通信程序
- 简单的程序设计大赛流程
- Qt菜单、文件、信号与槽最简单程序
- 第十五周任务一 用MFC能设计最简单的窗口程序。
- Linux内核设计第二周学习总结 完成一个简单的时间片轮转多道程序内核代码
- 一步一步跟我学易语言之第二个易程序菜单设计
- 八条设计多线程程序的简单规则
- 用C#编写一个简单记事本程序(上)
- 【项目】优化算法设计(二):程序的简单实现
- 由一个简单的客户端间TCP/UDP通信程序引发的关于设计模式的思考
- 【2009】设计一个简单的编码、解码程序
- Python设计足球联赛赛程表程序的思路与简单实现示例