熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

c#記事本實現代碼

2022-06-13   來源: .NET編程 

  編輯模塊只實現了全選和時間個功能自動換行的功能還沒寫

  如果需要全部源碼的請留言或者發郵件至hen

  版本

  主要代碼如下

  using System;
using SystemCollectionsGeneric;
using SystemComponentModel;
using SystemData;
using SystemDrawing;
using SystemText;
using SystemWindowsForms;
using SystemIO;

  namespace MyNotePad
{
public partial class MyNotePad : Form
{
public MyNotePad()
{
InitializeComponent();
thistoolStripStatusLabelText = DateTimeNowDayOfWeekToString();
}

  private void textBox_KeyPress(object sender KeyPressEventArgs e)
{
//textBoxText += eKeyChar;
}

  private void 退出ToolStripMenuItem_Click(object sender EventArgs e)
{
ApplicationExit();
}

  private void 日期ToolStripMenuItem_Click(object sender EventArgs e)
{
if (thistextBoxSelectedText != )
{
thistextBoxSelectedText = DateTimeNowToString();
}
else
{
thistextBoxText += DateTimeNow;
}
}

  private void timer_Tick(object sender EventArgs e)
{
thistoolStripStatusLabelText = 現在時間是: + DateTimeNowToString();
}

  private void 狀態欄ToolStripMenuItem_Click(object sender EventArgs e)
{
if (thisstatusStripVisible == false)
{
thisstatusStripVisible = true;
}
else
{
thisstatusStripVisible = false;
thistextBoxHeight += ;
}
}

  private void 關於MyNotePadAToolStripMenuItem_Click(object sender EventArgs e)
{
About ab = new About();
abShow();
}

  private void 全選ToolStripMenuItem_Click(object sender EventArgs e)
{
thistextBoxSelectAll();
}

  private void 字體ToolStripMenuItem_Click(object sender EventArgs e)
{
if (fontDialogShowDialog() == DialogResultOK)
{
textBoxFont = fontDialogFont;
}
}

  private void MyNotePad_Resize(object sender EventArgs e)
{
thispanelWidth = thisSizeWidth ;
thispanelHeight = thisSizeHeight ;
thistextBoxWidth = thispanelWidth;
thistextBoxHeight = thispanelHeight;
}

  private void 自動換行ToolStripMenuItem_Click(object sender EventArgs e)
{

  }

  private void 保存ToolStripMenuItem_Click(object sender EventArgs e)
{
using (SaveFileDialog saveDig = new SaveFileDialog())
{
saveDigFilter = @文本文檔(*txt)|*txt;
saveDigFileName = *txt;
if (saveDigShowDialog() == DialogResultOK)
{
StreamWriter sw = new StreamWriter(saveDigFileName false SystemTextEncodingDefault);
swWrite(thistextBoxText);
swClose();
thisText = saveDigFileName;
}
}
}

  private void 另存為ToolStripMenuItem_Click(object sender EventArgs e)
{
using (SaveFileDialog saveDig = new SaveFileDialog())
{
saveDigFilter = @文本文檔(*txt)|*txt;
saveDigFileName = thisText;
if (saveDigShowDialog() == DialogResultOK)
{
StreamWriter sw = new StreamWriter(saveDigFileName false SystemTextEncodingDefault);
swWrite(thistextBoxText);
swClose();
}
}
}

  private void 新建ToolStripMenuItem_Click(object sender EventArgs e)
{
if (thistextBoxText != )
{

  DialogResult d = MessageBoxShow(文件 + thisText + @ 的文字已經改變

  想保存文件嗎? MyNotePad MessageBoxButtonsYesNoCancel MessageBoxIconInformation MessageBoxDefaultButtonButton MessageBoxOptionsDefaultDesktopOnly)

  switch (d)
{
case DialogResultYes:
using (SaveFileDialog saveDig = new SaveFileDialog())
{
saveDigFilter = @文本文檔(*txt)|*txt;
saveDigFileName = *txt;
if (saveDigShowDialog() == DialogResultOK)
{
StreamWriter sw = new StreamWriter(saveDigFileName false SystemTextEncodingDefault);
swWrite(thistextBoxText);
swClose();
thisText = saveDigFileName;
}
}
break;
case DialogResultNo:
thistextBoxText = ;
break;
case DialogResultCancel:
break;

  default: SystemDiagnosticsDebugAssert(false);
break;

  }

  }
}

  private void 打開ToolStripMenuItem_Click(object sender EventArgs e)
{
if (thistextBoxText != )
{

  DialogResult d = MessageBoxShow(文件 + thisText + @ 的文字已經改變

  想保存文件嗎? MyNotePad MessageBoxButtonsYesNoCancel MessageBoxIconInformation MessageBoxDefaultButtonButton MessageBoxOptionsDefaultDesktopOnly)

  

  switch (d)
{
case DialogResultYes:
using (SaveFileDialog saveDig = new SaveFileDialog())
{
saveDigFilter = @文本文檔(*txt)|*txt;
saveDigFileName = *txt;
if (saveDigShowDialog() == DialogResultOK)
{
StreamWriter sw = new StreamWriter(saveDigFileName false SystemTextEncodingDefault);
swWrite(thistextBoxText);
swClose();
thisText = saveDigFileName;
}
}
break;
case DialogResultNo:
thistextBoxText = ;
break;
case DialogResultCancel:
break;

  default: SystemDiagnosticsDebugAssert(false);
break;

  }
}
else
{
using (OpenFileDialog dlgText = new OpenFileDialog())
{
dlgTextFilter = @(*txt)|*txt;
if (dlgTextShowDialog() == DialogResultOK)
{
if (FileExists(dlgTextFileName))
{
StreamReader rStream = new StreamReader(dlgTextFileName SystemTextEncodingDefault);
string s=default(string);
thistextBoxText = ;
while ((s = rStreamReadLine()) != null)
{
thistextBoxText += s;
}
rStreamClose();
}
}
}
}
}

  private void MyNotePad_FormClosing(object sender FormClosingEventArgs e)
{
if (thistextBoxText != )
{

  DialogResult d = MessageBoxShow(文件 + thisText + @ 的文字已經改變

  想保存文件嗎? MyNotePad MessageBoxButtonsYesNoCancel MessageBoxIconInformation MessageBoxDefaultButtonButton MessageBoxOptionsDefaultDesktopOnly)

  switch (d)
{
case DialogResultYes:
using (SaveFileDialog saveDig = new SaveFileDialog())
{
saveDigFilter = @文本文檔(*txt)|*txt;
saveDigFileName = *txt;
if (saveDigShowDialog() == DialogResultOK)
{
StreamWriter sw = new StreamWriter(saveDigFileName false SystemTextEncodingDefault);
swWrite(thistextBoxText);
swClose();
thisText = saveDigFileName;
}
}
break;
case DialogResultNo:
break;
case DialogResultCancel:
break;

  default: SystemDiagnosticsDebugAssert(false);
break;

  }
}
}

  }
}

    其他代碼可以省略吧


From:http://tw.wingwit.com/Article/program/net/201311/11890.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.