剛弄的一個小程式~ NotePad
TWed2k-NodePad (6K, 右鍵-另存新檔)
才用了278行的代碼就可以寫出來~ 真的好方便~ 
代碼如下:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace WindowsApplication1
{
/// <summary>
/// Summary description for Form1.
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.RichTextBox MyRTBox;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.StatusBar MyStatus;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem7;
private System.Windows.Forms.OpenFileDialog openFileDialog1;
private System.Windows.Forms.SaveFileDialog saveFileDialog1;
private System.Windows.Forms.PrintPreviewDialog printPreviewDialog1;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/// <summary>
/// Clean up any resources being used.
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Form1));
this.MyRTBox = new System.Windows.Forms.RichTextBox();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.MyStatus = new System.Windows.Forms.StatusBar();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.printPreviewDialog1 = new System.Windows.Forms.PrintPreviewDialog();
this.SuspendLayout();
//
// MyRTBox
//
this.MyRTBox.Dock = System.Windows.Forms.DockStyle.Fill;
this.MyRTBox.Location = new System.Drawing.Point(0, 0);
this.MyRTBox.Name = "MyRTBox";
this.MyRTBox.Size = new System.Drawing.Size(292, 266);
this.MyRTBox.TabIndex = 0;
this.MyRTBox.Text = "";
this.MyRTBox.TextChanged += new System.EventHandler(this.MyRTBox_TextChanged);
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem7});
//
// MyStatus
//
this.MyStatus.Location = new System.Drawing.Point(0, 244);
this.MyStatus.Name = "MyStatus";
this.MyStatus.Size = new System.Drawing.Size(292, 22);
this.MyStatus.TabIndex = 1;
this.MyStatus.Text = "New File";
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem4,
this.menuItem5,
this.menuItem6});
this.menuItem1.Text = "&File";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "&New File";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "&Open File";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.Text = "&Save File";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// menuItem5
//
this.menuItem5.Index = 3;
this.menuItem5.Text = "-";
//
// menuItem6
//
this.menuItem6.Index = 4;
this.menuItem6.Text = "&Exit";
this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
//
// menuItem7
//
this.menuItem7.Index = 1;
this.menuItem7.Text = "&About";
this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
//
// openFileDialog1
//
this.openFileDialog1.Filter = "Text Files(*.txt)|*.txt|Rich Text Format Files(*.rtf)|*.rtf|All Files(*.*)|*.*";
//
// saveFileDialog1
//
this.saveFileDialog1.Filter = "Text Files(*.txt)|*.txt|Rich Text Format Files(*.rtf)|*.rtf|All Files(*.*)|*.*";
//
// printPreviewDialog1
//
this.printPreviewDialog1.AutoScrollMargin = new System.Drawing.Size(0, 0);
this.printPreviewDialog1.AutoScrollMinSize = new System.Drawing.Size(0, 0);
this.printPreviewDialog1.ClientSize = new System.Drawing.Size(400, 300);
this.printPreviewDialog1.Enabled = true;
this.printPreviewDialog1.Icon = ((System.Drawing.Icon)(resources.GetObject("printPreviewDialog1.Icon")));
this.printPreviewDialog1.Location = new System.Drawing.Point(132, 174);
this.printPreviewDialog1.MinimumSize = new System.Drawing.Size(375, 250);
this.printPreviewDialog1.Name = "printPreviewDialog1";
this.printPreviewDialog1.TransparencyKey = System.Drawing.Color.Empty;
this.printPreviewDialog1.Visible = false;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 266);
this.Controls.Add(this.MyStatus);
this.Controls.Add(this.MyRTBox);
this.Menu = this.mainMenu1;
this.Name = "Form1";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "NotePad (TWed2k Version)";
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
MyNewFile();
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
MyOpenFile();
}
private void menuItem4_Click(object sender, System.EventArgs e)
{
MySaveFile();
}
private void menuItem6_Click(object sender, System.EventArgs e)
{
MyExit();
}
private void MyNewFile()
{
CheckSave();
MyRTBox.Clear();
MyStatus.Text="New File";
}
private void MyOpenFile()
{
CheckSave();
if(openFileDialog1.ShowDialog()==DialogResult.OK)
{
MyRTBox.LoadFile(openFileDialog1.FileName, RichTextBoxStreamType.PlainText);
MyStatus.Text="Open File";
Form1.ActiveForm.Text = openFileDialog1.FileName + " - NotePad";
}
}
private void MySaveFile()
{
MyStatus.Text = "Save File";
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
MyRTBox.SaveFile(saveFileDialog1.FileName, RichTextBoxStreamType.PlainText);
}
}
private void CheckSave()
{
if (MyRTBox.Text != "")
{
if (MessageBox.Show("Save the current document?", "Confirm", MessageBoxButtons.OKCancel) == DialogResult.OK)
{
MySaveFile();
}
}
}
private void MyExit()
{
CheckSave();
Application.Exit();
}
private void MyRTBox_TextChanged(object sender, System.EventArgs e)
{
MyStatus.Text="Editing File";
}
private void menuItem7_Click(object sender, System.EventArgs e)
{
MessageBox.Show("Author: Vic \nBuild.001 -- 2004", "Credit", MessageBoxButtons.OK);
}
}
}