📄 form1.cs
字号:
}
zijie = textShow.Text.Length;
}
else if (result == DialogResult.No)
{
textShow.Text = "";
filePath = null;
}
else
{
return;
}
}
}
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (textShow.Text == "" || textShow.Text == null || zijie == this.textShow.Text.Length)
{
Application.Exit();
}
else
{
DialogResult result = MessageBox.Show("文件" + filePath + "已发生改变是否保存", "提示", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Exclamation);
if (result == DialogResult.Yes)
{
if (filePath == null)
{
另存为ToolStripMenuItem_Click(this, null);
}
else
{
FileStream fs = new FileStream(filePath, FileMode.Create);
try
{
string inshow = textShow.Text;
UTF8Encoding encodeing = new UTF8Encoding(true);
byte[] by = encodeing.GetBytes(inshow);
fs.Write(by, 0, by.Length);
}
catch (Exception er)
{
MessageBox.Show(er.Message);
}
finally
{
fs.Flush();
fs.Close();
}
}
zijie = textShow.Text.Length;
}
if (result == DialogResult.No)
{
//**********************************
//Application.Exit();关闭
}
if (result == DialogResult.Cancel)
{
e.Cancel = true;
}
}
}
private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void 日期ToolStripMenuItem_Click(object sender, EventArgs e)
{
DateTime myDateTime = DateTime.UtcNow;
textShow .Text +=myDateTime.ToString();
}
private void 关于此记事本ToolStripMenuItem_Click(object sender, EventArgs e)
{
Form2 n = new Form2();
n.ShowDialog();
}
private void 自动换行ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.textShow.WordWrap)
{
this.textShow.WordWrap = false;
this.自动换行ToolStripMenuItem.Text = "自动换行(&W)";
statusStrip1.Visible = false;
df = false;
}
else
{
this.textShow.WordWrap = true;
this.自动换行ToolStripMenuItem.Text = "√" + this.自动换行ToolStripMenuItem.Text;
}
}
private void 查看GToolStripMenuItem_Click(object sender, EventArgs e)
{
if (自动换行ToolStripMenuItem.Text == "自动换行(&W)")
{
状态栏ToolStripMenuItem.Enabled = false;
}
else
{
状态栏ToolStripMenuItem.Enabled = true ;
}
}
private void 状态栏ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (df==false)
{
statusStrip1.Visible =true ;
df = true;
}else if (df ==true )
{
statusStrip1.Visible = false ;
df = false ;
}
}
private void timer2_Tick(object sender, EventArgs e)
{
toolStripStatusLabel1.Visible = true;
toolStripStatusLabel2.Visible = true;
toolStripStatusLabel2.Text =Convert .ToString ( DateTime.Now);
toolStripStatusLabel6.Text =" "+textShow.Text .Length;
}
private void 查看GToolStripMenuItem_MouseEnter(object sender, EventArgs e)
{
this.查看GToolStripMenuItem_Click(this,null );
}
private void toolStripMenuItem3_Click(object sender, EventArgs e)
{
if (textShow.SelectionLength > 0)
// Copy the selected text to the Clipboard.
textShow.Copy();
}
private void toolStripMenuItem4_Click(object sender, EventArgs e)
{
if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == true)
{
// Determine if any text is selected in the text box.
//if (textShow.SelectionLength > 0)
//{
// // Ask user if they want to paste over currently selected text.
// if (MessageBox.Show("Do you want to paste over current selection?", "Cut Example", MessageBoxButtons.YesNo) == DialogResult.No)
// // Move selection to the point after the current selection and paste.
// textShow.SelectionStart = textShow.SelectionStart + textShow.SelectionLength;
//}
// Paste current text in Clipboard into text box.
textShow.Paste();
}
}
private void toolStripMenuItem2_Click_1(object sender, EventArgs e)
{
if (textShow.SelectedText != "")
// Cut the selected text in the control and paste it into the Clipboard.
textShow.Cut();
}
private void 编辑ToolStripMenuItem_Click(object sender, EventArgs e)
{
if (textShow.SelectionLength == 0)
{
toolStripMenuItem3.Enabled = false;
toolStripMenuItem2.Enabled = false;
toolStripMenuItem5.Enabled = false;
}
else if (textShow.SelectionLength > 0)
{
toolStripMenuItem5.Enabled = true;
toolStripMenuItem3.Enabled = true ;
toolStripMenuItem2.Enabled = true;
}
if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == false)
{
toolStripMenuItem4.Enabled = false;
}
else if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == true)
{
toolStripMenuItem4.Enabled = true ;
}
}
private void 编辑ToolStripMenuItem_MouseEnter(object sender, EventArgs e)
{
this.编辑ToolStripMenuItem_Click(this, null);
}
private void toolStripMenuItem5_Click(object sender, EventArgs e)
{
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -