C#:C# 以前的一个简单的记事…
2014-06-12 13:51
471 查看
//当时不懂,如果谁看到这个文章,不要怪啊,我是写给自己看的
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.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace 记事本_尝试版_
{
public partial class
Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void FileSave(string name)
{
try
{
textBox1.Text = textBox1.Text
+DateTime.Now;
IFormatter formater = new
BinaryFormatter();
Stream stream2 = new
FileStream(name, FileMode.Create, FileAccess.Write);
formater.Serialize(stream2,
textBox1.Text);
stream2.Close();
}
catch
(Exception ee)
{
MessageBox.Show(ee.Message);
}
}
public void FileOpen(string name)
{
IFormatter
formater1 = new BinaryFormatter();
Stream
stream1 = new FileStream(name, FileMode.Open,
FileAccess.Read);
textBox1.Text = formater1.Deserialize(stream1).ToString();
stream1.Close();
}
private void 打开ToolStripMenuItem_Click(object
sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.InitialDirectory = @"..\\";
open.Filter = "text文件|*.text";
if
(open.ShowDialog() == DialogResult.OK)
{
FileOpen(open.FileName.ToString());
}
}
private void 保存ToolStripMenuItem_Click(object
sender, EventArgs e)
{
SaveFileDialog othersave = new SaveFileDialog();
othersave.Filter = "text文件|*.text";
othersave.ShowDialog();
string
filename = othersave.FileName;
FileSave(filename);
MessageBox.Show("保存成功!");
}
private void 另存为ToolStripMenuItem_Click(object
sender, EventArgs e)
{
SaveFileDialog othersave = new SaveFileDialog();
othersave.Filter = "text文件|*.text";
othersave.ShowDialog();
string
filename = othersave.FileName;
FileSave(filename);
}
private void 关闭ToolStripMenuItem_Click(object
sender, EventArgs e)
{
if
(MessageBox.Show("确定要关闭文档?", "关闭文档", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) == DialogResult.OK)
{
Application.Exit(); }
}
private void 颜色ToolStripMenuItem_Click(object
sender, EventArgs e)
{
ColorDialog color = new ColorDialog();
if
(color.ShowDialog() == DialogResult.OK)
{
textBox1.ForeColor =
color.Color;
}
}
private void 字体ToolStripMenuItem1_Click(object
sender, EventArgs e)
{
FontDialog
font = new FontDialog();
if
(font.ShowDialog() == DialogResult.OK)
{
textBox1.Font =
font.Font;
}
}
private void 背景ToolStripMenuItem_Click(object
sender, EventArgs e)
{
ColorDialog color = new ColorDialog();
if
(color.ShowDialog() == DialogResult.OK)
{
textBox1.BackColor =
color.Color;
}
}
private void 联系作者ToolStripMenuItem_Click(object
sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://652768664.qzone.qq.com");
}
private void Form1_Load(object sender, EventArgs
e)
{
label1.Text =
"系统当前时间:"+DateTime.Now.ToString();
}
private void 粘贴ToolStripMenuItem_Click(object
sender, EventArgs e)
{
textBox1.Text=textBox1.Text+" "+Clipboard.GetText();
}
private void 清空文本ToolStripMenuItem_Click(object
sender, EventArgs e)
{
textBox1.Text = "";
}
private void 全选ToolStripMenuItem_Click(object
sender, EventArgs e)
{
textBox1.SelectAll();
}
private void 复制ToolStripMenuItem_Click(object
sender, EventArgs e)
{
IDataObject copy = Clipboard.GetDataObject();
copy.GetDataPresent(DataFormats.Text);
}
}
}
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.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
namespace 记事本_尝试版_
{
public partial class
Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public void FileSave(string name)
{
try
{
textBox1.Text = textBox1.Text
+DateTime.Now;
IFormatter formater = new
BinaryFormatter();
Stream stream2 = new
FileStream(name, FileMode.Create, FileAccess.Write);
formater.Serialize(stream2,
textBox1.Text);
stream2.Close();
}
catch
(Exception ee)
{
MessageBox.Show(ee.Message);
}
}
public void FileOpen(string name)
{
IFormatter
formater1 = new BinaryFormatter();
Stream
stream1 = new FileStream(name, FileMode.Open,
FileAccess.Read);
textBox1.Text = formater1.Deserialize(stream1).ToString();
stream1.Close();
}
private void 打开ToolStripMenuItem_Click(object
sender, EventArgs e)
{
OpenFileDialog open = new OpenFileDialog();
open.InitialDirectory = @"..\\";
open.Filter = "text文件|*.text";
if
(open.ShowDialog() == DialogResult.OK)
{
FileOpen(open.FileName.ToString());
}
}
private void 保存ToolStripMenuItem_Click(object
sender, EventArgs e)
{
SaveFileDialog othersave = new SaveFileDialog();
othersave.Filter = "text文件|*.text";
othersave.ShowDialog();
string
filename = othersave.FileName;
FileSave(filename);
MessageBox.Show("保存成功!");
}
private void 另存为ToolStripMenuItem_Click(object
sender, EventArgs e)
{
SaveFileDialog othersave = new SaveFileDialog();
othersave.Filter = "text文件|*.text";
othersave.ShowDialog();
string
filename = othersave.FileName;
FileSave(filename);
}
private void 关闭ToolStripMenuItem_Click(object
sender, EventArgs e)
{
if
(MessageBox.Show("确定要关闭文档?", "关闭文档", MessageBoxButtons.OKCancel,
MessageBoxIcon.Question) == DialogResult.OK)
{
Application.Exit(); }
}
private void 颜色ToolStripMenuItem_Click(object
sender, EventArgs e)
{
ColorDialog color = new ColorDialog();
if
(color.ShowDialog() == DialogResult.OK)
{
textBox1.ForeColor =
color.Color;
}
}
private void 字体ToolStripMenuItem1_Click(object
sender, EventArgs e)
{
FontDialog
font = new FontDialog();
if
(font.ShowDialog() == DialogResult.OK)
{
textBox1.Font =
font.Font;
}
}
private void 背景ToolStripMenuItem_Click(object
sender, EventArgs e)
{
ColorDialog color = new ColorDialog();
if
(color.ShowDialog() == DialogResult.OK)
{
textBox1.BackColor =
color.Color;
}
}
private void 联系作者ToolStripMenuItem_Click(object
sender, EventArgs e)
{
System.Diagnostics.Process.Start("http://652768664.qzone.qq.com");
}
private void Form1_Load(object sender, EventArgs
e)
{
label1.Text =
"系统当前时间:"+DateTime.Now.ToString();
}
private void 粘贴ToolStripMenuItem_Click(object
sender, EventArgs e)
{
textBox1.Text=textBox1.Text+" "+Clipboard.GetText();
}
private void 清空文本ToolStripMenuItem_Click(object
sender, EventArgs e)
{
textBox1.Text = "";
}
private void 全选ToolStripMenuItem_Click(object
sender, EventArgs e)
{
textBox1.SelectAll();
}
private void 复制ToolStripMenuItem_Click(object
sender, EventArgs e)
{
IDataObject copy = Clipboard.GetDataObject();
copy.GetDataPresent(DataFormats.Text);
}
}
}
相关文章推荐
- c# 一个简单的加密解密算法
- 一个简单的图片拖拽排序效果   -----   JQUERY特效模板
- 一个简单的socket DEMO
- 自己以前用C#写的简单升级程序源码(比如更新一个安装包或者压缩文件),带进度条,支持续传
- C# List<>简单用法
- 一个简单的XML Schema的例子
- C# List<>简单用法
- 用C#编写一个简单记事本程序(上)
- C#:C# Process打开一个网址,…
- C#编写一个简单记事本功能
- Mobile&nbsp;Web&nbsp;App一个页面的简单的东…
- 分形介绍 && 一个简单的Kotch curve实现代码
- 利用C#编写一个简单的抓网页应用程序
- 一个简单的动态编译器,支持C#和VB.NET。当你想测试一些简单的代码的时候可以使用。
- 利用C#编写一个简单的抓网页应用程序
- 用C#制作一个最简单的Web Service
- 使用C#开发一个简单的P2P应用
- 如何用C#写一个简单的Login窗口
- 一个简单实用的sql数据库查询工具(c#)
- 用C#写一个简单的WINDOWS服务程序