The editing module only implements the full selection and time 2 functions, the automatic line wrapping function has not written.
If you need all the source, please leave a message or send an email to henanlinzhoulcl@163.com
Version: 1.0
The main code is as follows:
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 Mynotepad
{
public partial class Mynotepad:form
{
public Mynotepad ()
{
InitializeComponent ();
This.toolStripStatusLabel3.Text = DateTime.Now.DayOfWeek.ToString ();
}
private void Textbox1_keypress (object sender, KeyPressEventArgs e)
{
//textbox1.text + = E.keychar;
}
private void Exits Toolstripmenuitem_click (object sender, EventArgs e)
{
Application.exit ();
}
private void Date Toolstripmenuitem_click (object sender, EventArgs e)
{
if (this.textBox1.SelectedText!= "")
{
This.textBox1.SelectedText = DateTime.Now.ToString ();
}
Else
{
This.textBox1.Text + = DateTime.Now;
}
}
private void Timer1_Tick (object sender, EventArgs e)
{
This.toolStripStatusLabel1.Text = "Now time is:" + DateTime.Now.ToString ();
}
private void status bar Toolstripmenuitem_click (object sender, EventArgs e)
{
if (this.statusStrip1.Visible = = False)
{
this.statusStrip1.Visible = true;
}
Else
{
this.statusStrip1.Visible = false;
This.textBox1.Height + + 10;
}
}
private void about Mynotepadatoolstripmenuitem_click (object sender, EventArgs e)
{
about AB = new about ();
AB. Show ();
}
private void Full selection Toolstripmenuitem_click (object sender, EventArgs e)
{
This.textBox1.SelectAll ();
}
private void Font Toolstripmenuitem_click (object sender, EventArgs e)
{
if (fontdialog1.showdialog () = = DialogResult.OK)
{
Textbox1.font = Fontdialog1.font;
}
}
private void Mynotepad_resize (object sender, EventArgs e)
{
This.panel1.Width = this. size.width-25;
This.panel1.Height = this. size.height-50;
this.textBox1.Width = this.panel1.Width;
this.textBox1.Height = this.panel1.Height;
}
private void Automatic wrapping Toolstripmenuitem_click (object sender, EventArgs e)
{
}
private void Save Toolstripmenuitem_click (object sender, EventArgs e)
{
using (SaveFileDialog Savedig = new SaveFileDialog ())
{
Savedig.filter = @ "text document (*.txt) |*.txt";
savedig.filename = "*.txt";
if (savedig.showdialog () = = DialogResult.OK)
{
StreamWriter sw = new StreamWriter (Savedig.filename, False, System.Text.Encoding.Default);
SW. Write (This.textBox1.Text);
SW. Close ();
this. Text = Savedig.filename;
}
}
}
private void is saved as Toolstripmenuitem_click (object sender, EventArgs e)
{
using (SaveFileDialog Savedig = new SaveFileDialog ())
{
Savedig.filter = @ "text document (*.txt) |*.txt";
Savedig.filename = this. Text;
if (savedig.showdialog () = = DialogResult.OK)
{
StreamWriter sw = new StreamWriter (Savedig.filename, False, System.Text.Encoding.Default);
SW. Write (This.textBox1.Text);
SW. Close ();
}
}
}
private void new Toolstripmenuitem_click (object sender, EventArgs e)
{
if (this.textBox1.Text!= "")
{
DialogResult d = MessageBox.Show ("file" + this. Text + @ "has changed.
Do you want to save the file? "," Mynotepad, Messageboxbuttons.yesnocancel, MessageBoxIcon.Information, Messageboxdefaultbutton.button1, MESSAGEBOXOPTIONS.DEFAULTDESKTOPONLY);
switch (d)
{
case DialogResult.Yes:
using (SaveFileDialog saveDig = new SaveFileDialog())
{
saveDig.Filter = @"文本文档(*.txt)|*.txt";
saveDig.FileName = "*.txt";
if (saveDig.ShowDialog() == DialogResult.OK)
{
StreamWriter sw = new StreamWriter(saveDig.FileName, false, System.Text.Encoding.Default);
sw.Write(this.textBox1.Text);
sw.Close();
this.Text = saveDig.FileName;
}
}
break;
case DialogResult.No:
this.textBox1.Text = "";
break;
case DialogResult.Cancel:
break;
default: System.Diagnostics.Debug.Assert(false);
break;
}
}
}
private void 打开ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.textBox1.Text != "")
{
DialogResult d = MessageBox.Show ("file" + this. Text + @ "has changed.
Do you want to save the file? "," Mynotepad, Messageboxbuttons.yesnocancel, MessageBoxIcon.Information, Messageboxdefaultbutton.button1, MESSAGEBOXOPTIONS.DEFAULTDESKTOPONLY);
switch (d)
{
Case dialogresult.yes:
using (SaveFileDialog Savedig = new SaveFileDialog ())
{
S Avedig.filter = @ "text document (*.txt) |*.txt";
Savedig.filename = "*.txt";
if (savedig.showdialog () = DialogResult.OK)
{
StreamWriter sw = new StreamWriter (Savedig.filename, False, Sy Stem. Text.Encoding.Default);
SW. Write (This.textBox1.Text);
SW. Close ();
this. Text = Savedig.filename;
}
break;
Case dialogresult.no:
This.textBox1.Text = ";
Break
Case DialogResult.Cancel:
break;
Default:System.Diagnostics.Debug.Assert (FALSE);
break;
}
}
Else
{
using (OpenFileDialog dlgtext = new OpenFileDialog ())
{
Dlgtext.filter = @ "(* . txt) |*.txt ";
if (dlgtext.showdialog () = DialogResult.OK)
{
if (file.exists (dlgtext.filename))
{
StreamReader Rstream = new StreamReader (Dlgtext.filename, System.Text.Encoding.Default);
String S=default (String);
This.textbox1. Text = "";
while ((s = rstream.readline ())!= null)
{
This.textBox1.Text = = s;
}
Rstream.close ();
}
}
}
}
private void Mynotepad_formclosing (object sender, FormClosingEventArgs e)
{
if (This.textBox1.Text!= "")
{
DialogResult d = MessageBox.Show ("file" + this. Text + @ "has changed.
Do you want to save the file? "," Mynotepad, Messageboxbuttons.yesnocancel, MessageBoxIcon.Information, Messageboxdefaultbutton.button1, MESSAGEBOXOPTIONS.DEFAULTDESKTOPONLY);
switch (d)
{
case DialogResult.Yes:
using (SaveFileDialog saveDig = new SaveFileDialog())
{
saveDig.Filter = @"文本文档(*.txt)|*.txt";
saveDig.FileName = "*.txt";
if (saveDig.ShowDialog() == DialogResult.OK)
{
StreamWriter sw = new StreamWriter(saveDig.FileName, false, System.Text.Encoding.Default);
sw.Write(this.textBox1.Text);
sw.Close();
this.Text = saveDig.FileName;
}
}
break;
case DialogResult.No:
break;
case DialogResult.Cancel:
break;
default: System.Diagnostics.Debug.Assert(false);
break;
}
}
}
}
}
Other code can be omitted.