c#

位置:IT落伍者 >> c# >> 浏览文章

c#记事本实现代码


发布日期:2018年08月03日
 
c#记事本实现代码

编辑模块只实现了全选和时间个功能自动换行的功能还没写

如果需要全部源码的请留言或者发邮件至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;

}

}

}

}

}

其他代码可以省略吧

上一篇:.NET 2.0远程传输数据集的优化方法

下一篇:C#调用JS的几种方法