- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.IO;
- namespace WindowsApplication2
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private string text = string.Empty;
- private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
- {
- e.Graphics.DrawString(richTextBox1.Text, new Font("Arial", 10), Brushes.Black, 20, 20); //将要打印的文本输出到printDocument
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- toolStripStatusLabel4.Text = "Copyright © 2008 xiaomeng Inc. All Rights Reserved";
- richTextBox1.EnableAutoDragDrop = true; //设置允许拖放对象
- richTextBox1.DragDrop += new DragEventHandler(richTextBox1_DragDrop); //注册拖放事件
- //if (e.KeyCode == Keys.F1) { MessageBox.Show("该软件由孟德军编写,版权所有,侵权必究!", "关于"); }
- }
- public void loadinfo(String path) {
- StreamReader fw = new StreamReader(path, System.Text.Encoding.GetEncoding("gb2312"), true);
- // StreamReader fw = new StreamReader(path,System.Text.Encoding.Default,true);
- richTextBox1.Text = fw.ReadToEnd();
- fw.Close();
- //创建一个输入流。并将输出流存入到richtextbox中。
- }
- public void saveinfo(String path)
- {
- StreamWriter fi = new StreamWriter(path);
- fi.WriteLine(richTextBox1.Text);
- fi.Close();
- //创建一个输出流。并将richtextbox保存在文件中。输出到文件。
- }
- private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- OpenFileDialog dlg = new OpenFileDialog();
- dlg.InitialDirectory = Application.StartupPath;//启动应用程序的路径。
- dlg.Filter = "文本文件|*.txt";//文件类型中出现的内容。
- if (dlg.ShowDialog() == DialogResult.OK) {
- loadinfo(dlg.FileName);//挑用方法。
- //--------------------------------------------------------------------------------
- /* string strName = dlg.FileName;
- string str1;
- str1 = Path.GetFileNameWithoutExtension(dlg.FileName) + "/n";
- richTextBox1.Name = str1;*/
- //
- }
- }
- private void 保存ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- SaveFileDialog dlm = new SaveFileDialog();
- dlm.InitialDirectory = Application.StartupPath;
- dlm.Filter = "文本文件|*.txt";
- if (dlm.ShowDialog() == DialogResult.OK) { saveinfo(dlm.FileName); }
- }
- private void timer1_Tick(object sender, EventArgs e)
- {
- toolStripStatusLabel1.Text ="本地坐标::"+Cursor.Position.X.ToString() +" "+ Cursor.Position.Y.ToString();
- }
- private void 关闭ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (richTextBox1.Text=="")
- {
- this.Close();
- }
- else
- { //MessageBox.Show("文件尚未保存,请确定要退出吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
- if (MessageBox.Show("文件尚未保存,请确定要退出吗?", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
- {
- this.Close();
- }
- }
- }
- private void copyToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Clipboard.SetDataObject(richTextBox1.Text);
- }
- private void clipToolStripMenuItem_Click(object sender, EventArgs e)
- {
- IDataObject idata = Clipboard.GetDataObject();
- if (idata.GetDataPresent(DataFormats.Text))
- {
- this.richTextBox1.Text = this.richTextBox1.Text + (String)idata.GetData(DataFormats.Text);
- }
- else { MessageBox.Show("您没有复制任何数据!", "aboout", MessageBoxButtons.OK, MessageBoxIcon.Error); }
- }
- private void dateToolStripMenuItem_Click(object sender, EventArgs e)
- {
- richTextBox1.Text+=richTextBox1.Text.Insert(richTextBox1.TextLength,System.DateTime.Now.ToString());
- }
- private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
- {
- new Form2().Show();
- }
- private void 字体FToolStripMenuItem_Click(object sender, EventArgs e)
- {
- FontDialog font = new FontDialog();
- if (font.ShowDialog() == DialogResult.OK)
- richTextBox1.Font = font.Font;
- }
- private void 颜色CToolStripMenuItem_Click(object sender, EventArgs e)
- {
- ColorDialog color = new ColorDialog();
- if (color.ShowDialog() == DialogResult.OK)
- {
- richTextBox1.ForeColor = color.Color;
- }
- }
- private void 新建NToolStripMenuItem_Click(object sender, EventArgs e)
- {
- Form1 newform = new Form1();
- newform.SetDisplayRectLocation(0,0);
- newform.Show();
- newform.Text = "未命名文件";
- }
- private void 返回RToolStripMenuItem_Click(object sender, EventArgs e)
- {
- richTextBox1.Copy();
- }
- private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
- {
- }
- private void toolStripStatusLabel2_Click_1(object sender, EventArgs e)
- {
- }
- private void timer2_Tick(object sender, EventArgs e)
- {
- toolStripStatusLabel2.Text = "系统时间:" + System.DateTime.Now.ToString();
- }
- private void 预览VToolStripMenuItem_Click(object sender, EventArgs e)
- {
- //设于打印预览窗口所要关联的printDocument
- printPreviewDialog1.Document = printDocument1;
- try
- {
- printPreviewDialog1.ShowDialog(); //显示打印预览窗口
- }
- catch (Exception pr)
- {
- String message = pr.Message;
- MessageBox.Show("对不起,您可能还没有添加打印机!" + message, "打印错误", MessageBoxButtons.OK, MessageBoxIcon.Warning);
- if (printDialog1.ShowDialog() == DialogResult.OK) { this.Close(); }
- }
- }
- private void printPreviewDialog1_Load(object sender, EventArgs e)
- {
- }
- private void editToolStripMenuItem_Click(object sender, EventArgs e)
- {
- }
- private void 打印PToolStripMenuItem_Click(object sender, EventArgs e)
- {
- if (printDialog1.ShowDialog() == DialogResult.Cancel)
- {
- return; //返回
- }
- else //否则
- {
- printDocument1.Print(); //开始打印文档
- }
- }
- private void toolStripStatusLabel4_Click(object sender, EventArgs e)
- {
- toolStripStatusLabel4.Text = "Copyright © 2008 xiaomeng Inc. All Rights Reserved";
- System.Diagnostics.Process.Start("mailto:mak0000@msn.com");
- }
- private void toolStripStatusLabel3_Click(object sender, EventArgs e)
- {
- }
- private void richTextBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void richTextBox1_DragDrop(object sender, DragEventArgs e)
- {
- //获取拖放到控件上的文件路径,因为支持拖放多个,输出是一个数组!
- // richTextBox1.Text = ((string[])e.Data.GetData("FileName"))[0].ToString();
- MessageBox.Show(((string[])e.Data.GetData("FileName"))[0].ToString());
- // e.Effect = DragDropEffects.None;//设置拖放后的显示效果,这里设置无 */
- e.Effect = DragDropEffects.Copy;
- }
- private void 清除ToolStripMenuItem_Click(object sender, EventArgs e)
- {
- richTextBox1.Clear();
- }
- private void 剪切XToolStripMenuItem_Click(object sender, EventArgs e)
- {
- richTextBox1.Cut();
- }
- private void toolStripStatusLabel3_Click_1(object sender, EventArgs e)
- {
- }
- private void 目录IToolStripMenuItem_Click(object sender, EventArgs e)
- {
- folderBrowserDialog1.SelectedPath="C://";
- folderBrowserDialog1.ShowNewFolderButton = true;
- folderBrowserDialog1.Description = "请选择目录:";
- folderBrowserDialog1.ShowDialog();
- Text = folderBrowserDialog1.SelectedPath;
- }
- //仅仅显示文件名,实现打开功能就比较简单了
- #warning 这是一个测试各种对话框的软件。
- //#error 使用#error指令产生的信息
- #line 100 "Form1.cs"
- //author:xiaomeng
- }
- }
c# 记事本
最新推荐文章于 2023-07-26 13:29:20 发布