?? jishiben.cs
字號(hào):
?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;
using System.Drawing.Printing;
namespace jishiben
{
public partial class jishiben : Form
{
public static int replacecount = 0;
private searcher s;
private replace r;
private Editgoto gt;
private string filename,fname;
private bool filesaved = false;
private bool textChanged = false;
private bool finded = false;
private string findstring, sourstring;
private static string[] lines;
private static int selects = 0;
public static int Selects
{
get
{
return selects;
}
set
{
selects = value;
}
}
public static string[] Lines
{
get
{
return lines;
}
}
public jishiben()
{
InitializeComponent();
}
private void Filesaveas()
{
SaveFileDialog MyDialog = new SaveFileDialog();
MyDialog.InitialDirectory = "c:\\";
MyDialog.FileName = "MyText";
MyDialog.Filter = "Save files (*.txt)|*.txt|All files (*.*)|*.*";
if (MyDialog.ShowDialog() == DialogResult.OK)
{
this.filename = MyDialog.FileName;
Writefile();
}
}
private void Writefile()
{
StreamWriter writer = new StreamWriter(filename, false, System.Text.Encoding.Default);
writer.Write(tBtext.Text);
writer.Close();
char[] c = filename.ToCharArray();
int length = 0;
for (int i = filename.Length-1; i > 0; i--)
{
if(c[i]=='\\')
{
length=i+1;
break;
}
}
fname = filename.Remove(0,length);
this.Text = fname;
filesaved = true;
}
private void Fileopen()
{
OpenFileDialog MyDialog = new OpenFileDialog();
MyDialog.DefaultExt = "txt";
MyDialog.Filter = "Open files (*.txt)|*.txt";
if (MyDialog.ShowDialog() == DialogResult.OK)
{
tBtext.Clear();
this.filename = MyDialog.FileName;
Readfile();
filesaved = true;
textChanged = false;
tSMEdit_Undo.Enabled = false;
}
}
private void Readfile()
{
StreamReader reader = new StreamReader(filename, System.Text.Encoding.Default);
tBtext.Text = reader.ReadToEnd();
reader.Close();
char[] c = filename.ToCharArray();
int length = 0;
for (int i = filename.Length - 1; i > 0; i--)
{
if (c[i] == '\\')
{
length = i + 1;
break;
}
}
fname = filename.Remove(0, length);
this.Text = fname;
filesaved = true;
}
private void tSMFile_new_Click(object sender, EventArgs e)
{
if (tBtext.Text != "" && filesaved==false)
{
DialogResult a;
a = MessageBox.Show("文件沒(méi)有保存,你要保存嗎?", "沒(méi)有保存", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (a == DialogResult.Yes)
{
Filesaveas();
}
else
if (a == DialogResult.No)
{
tBtext.Clear();
this.Text = "新建 記事本";
this.filename = "";
}
}
if (filesaved || this.Text == "記事本")
{
tBtext.Clear();
this.Text = "新建 記事本";
this.filename = "";
}
}
private void tSMFile_open_Click(object sender, EventArgs e)
{
Fileopen();
}
private void tSMFile_save_Click(object sender, EventArgs e)
{
if (filename == null)
{
Filesaveas();
}
else
{
Writefile();
}
}
private void tSMFile_saveas_Click(object sender, EventArgs e)
{
Filesaveas();
}
private void tSMFile_quit_Click(object sender, EventArgs e)
{
this.Close();
}
private void tSMFile_print_Click(object sender, EventArgs e)
{
PrintDocument txt = new PrintDocument();
txt.DocumentName = this.filename;
PrintDialog MyDialog = new PrintDialog();
MyDialog.Document = txt;
try
{
MyDialog.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void tSMFile_pagesetup_Click(object sender, EventArgs e)
{
PrintDocument txt = new PrintDocument();
txt.DocumentName = this.filename;
PrintPreviewDialog MyDialog = new PrintPreviewDialog();
MyDialog.Document = txt;
try
{
MyDialog.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void tSMEdit_Undo_Click(object sender, EventArgs e)
{
tBtext.Undo();
}
private void tSMEdit_cut_Click(object sender, EventArgs e)
{
tBtext.Cut();
}
private void tSMEdit_copy_Click(object sender, EventArgs e)
{
tBtext.Copy();
}
private void tSMEdit_patse_Click(object sender, EventArgs e)
{
tBtext.Paste();
}
private void tSMEdit_delet_Click(object sender, EventArgs e)
{
tBtext.SelectedText = "";
}
private void tSMEdit_search_Click(object sender, EventArgs e)
{
s = new searcher();
s.Search += new searchEventHandler(searcher_Search);
s.Owner = this;
s.Show();
}
private void tSMEdit_chooseall_Click(object sender, EventArgs e)
{
tBtext.SelectAll();
}
private void tSMEdit_time_Click(object sender, EventArgs e)
{
DateTime now = DateTime.Now;
tBtext.SelectedText = now.ToString();
}
private void tSMSearch_statusbar_Click(object sender, EventArgs e)
{
tSMSearch_statusbar.Checked = !tSMSearch_statusbar.Checked;
if (tSMSearch_statusbar.Checked)
{
sSstatusbar.Visible = true;
}
else
{
sSstatusbar.Visible = false;
}
}
private void tSMFormat_autoline_Click(object sender, EventArgs e)
{
tSMFormat_autoline.Checked = !tSMFormat_autoline.Checked;
if (tSMFormat_autoline.Checked)
{
tBtext.WordWrap = true;
this.tSMEdit_goto.Enabled = false;
}
else
{
tBtext.WordWrap = false;
this.tSMEdit_goto.Enabled = true;
lines = tBtext.Lines;
//MessageBox.Show(tBtext.Lines[5].Length.ToString());
//MessageBox.Show(tBtext.SelectionStart.ToString());
tBtext.ScrollBars = RichTextBoxScrollBars.ForcedBoth;
}
}
private void tSMFormat_font_Click(object sender, EventArgs e)
{
FontDialog MyDialog = new FontDialog();
if (MyDialog.ShowDialog() == DialogResult.OK)
{
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -