- 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:[email protected]");
- }
- 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# 記事本
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.