VS编写的记事本源码

合集下载

记事本(代码)

记事本(代码)
{
char t; //选择是否继续输入
flag:
printf("请输入第%d个学生信息\n",a+1);
printf("学号:");
scanf("%d",&gt[a].xuehao);
printf("姓名:");
scanf("%s",&gt[a].name);
for(int k=i;k<a;k++)
if(gt[i].xuehao>gt[k].xuehao)
{
gts=gt[i];
gt[i]=gt[k];
gt[k]=gts;
}
{
for(l=0;l<a;l++)
{
gt[l]=gt[l+1];
}
}
}
if(x==2)
{
printf("请输入该学生的姓名\n");
scanf("%s",&q);
for (i=0;i<a;i++)
{
int l; //用于for循环
int i; //用于表示删除编号
int x; //选择
char q[10]; //被删除的姓名
int cx; //被删除的学号
printf("1.按学号删除\n");
char q[10]; //被修改的姓名
int cx; //被修改的学号
printf("1.按学号修改\n");
printf("2.按姓名修改\n");

记事本源代码

记事本源代码

记事本源代码先上效果图。

这个记事本操作简便,功能强⼤,在记事本的基础上添加了将内容发送短信和发送邮件的功能。

这个应⽤也已经功过了微软的认证。

115⽹盘⾥⾯的是最新的。

QQ:29992379下载地址:Memo.xap实体类1: public class Note2: {3: public string NoteGuid { get; set; }4: public string NoteContent { get; set; }5: public string NoteTime { get; set; }6: }在独⽴存储中⽣成存储结构。

1: if (!IsolatedStorageSettings.ApplicationSettings.Contains("Notes"))2: {3: List<Note> notes = new List<Note>();4: IsolatedStorageSettings.ApplicationSettings["Notes"] = notes as List<Note>;5: IsolatedStorageSettings.ApplicationSettings.Save();6:7: }绑定⽂章的列表,并按编号倒排序。

1: public partial class MainPage : PhoneApplicationPage2: {3: // 构造函数4: public MainPage()5: {6: InitializeComponent();7: BingData();8: }9: List<Note> notes = new List<Note>();10: private void BingData()11: {12: notes = IsolatedStorageSettings.ApplicationSettings["Notes"] as List<Note>;13:14: var descInfo = from i in notes orderby i.NoteTime descending select i;//linq对⽂章列表的排序15:16: MainListBox.ItemsSource = descInfo;17: }18:19: private void ApplicationBarIconButton_Click(object sender, EventArgs e)20: {21: NavigationService.Navigate(new Uri("/Add.xaml", UriKind.RelativeOrAbsolute));22: }23:24: protected override void OnBackKeyPress(ponentModel.CancelEventArgs e)25: {26: e.Cancel = true;27: App.Quit();28: base.OnBackKeyPress(e);29: }30:31: private void ApplicationBarIconButton_Click_1(object sender, EventArgs e)32: {33: NavigationService.Navigate(new Uri("/About.xaml", UriKind.RelativeOrAbsolute));34: }35:36: private void StackPanel_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)37: {38: string noteguid = ((TextBlock)(((StackPanel)sender).Children.First())).Tag.ToString();39: NavigationService.Navigate(new Uri("/DetailsPage.xaml?noteguid=" + noteguid, UriKind.Relative));40: }41: }⽂章显⽰的页⾯以及⼀系列功能1: public partial class DetailsPage : PhoneApplicationPage2: {3: // 构造函数4: public DetailsPage()5: {6: InitializeComponent();7: }8: string noteguid;9: protected override void OnNavigatedTo(NavigationEventArgs e)10: {11: BingData();12: noteguid = NavigationContext.QueryString["noteguid"].ToString();13: foreach (var item in notes)14: {15: if (item.NoteGuid==noteguid)16: {17: ContentText.Text = item.NoteContent;18: TimeText.Text = item.NoteTime;19: return;20: }21: }22: }23:24: List<Note> notes = new List<Note>();25: private void BingData()26: {27: notes = IsolatedStorageSettings.ApplicationSettings["Notes"] as List<Note>;28: }29:30: private void Edit_Click(object sender, EventArgs e)31: {32: NavigationService.Navigate(new Uri("/Edit.xaml?noteguid=" + noteguid.ToString(), UriKind.RelativeOrAbsolute)); 33: }34:35: protected override void OnBackKeyPress(ponentModel.CancelEventArgs e)36: {37: e.Cancel = true;38: NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));39: base.OnBackKeyPress(e);40: }41:42: private void Del_Click(object sender, EventArgs e)43: {44: for (int i = 0; i < notes.Count; i++)45: {46: if (notes[i].NoteGuid==noteguid)47: {48: notes.RemoveAt(i);49: }50: }51: IsolatedStorageSettings.ApplicationSettings["Notes"] = notes as List<Note>;52: IsolatedStorageSettings.ApplicationSettings.Save();53: NavigationService.Navigate(new Uri("/MainPage.xaml", UriKind.RelativeOrAbsolute));54: }55:56: private void Email_Click(object sender, EventArgs e)57: {58: EmailComposeTask email = new EmailComposeTask();59: email.Body = ContentText.Text.ToString();60: email.Show();61: }62:63: private void Message_Click(object sender, EventArgs e)64: {65: SmsComposeTask sms = new SmsComposeTask();66: sms.Body = ContentText.Text.ToString();67: sms.Show();68: }69: }⽂章的编辑页⾯代码1: public partial class Edit : PhoneApplicationPage2: {3: public Edit()4: {5: InitializeComponent();6: }7:8: private void ApplicationBarIconButton_Click(object sender, EventArgs e)9: {10: foreach (var item in notes)11: {12: if (item.NoteGuid == noteguid)13: {14: item.NoteContent = ContentText.Text;15: item.NoteTime=TimeText.Text;16: }17: }18:19: IsolatedStorageSettings.ApplicationSettings["Notes"] = notes as List<Note>;20: IsolatedStorageSettings.ApplicationSettings.Save();21: NavigationService.Navigate(new Uri("/DetailsPage.xaml?noteguid=" + noteguid.ToString(), UriKind.RelativeOrAbsolute)); 22: }23: string noteguid;24: protected override void OnNavigatedTo(NavigationEventArgs e)25: {26: BingData();27: noteguid = NavigationContext.QueryString["noteguid"].ToString();28: foreach (var item in notes)29: {30: if (item.NoteGuid==noteguid)31: {32: ContentText.Text = item.NoteContent;33: TimeText.Text = item.NoteTime;34: return;35: }36: }37: }38:39: List<Note> notes = new List<Note>();40: private void BingData()41: {42: notes = IsolatedStorageSettings.ApplicationSettings["Notes"] as List<Note>;43: }44: }。

vs2010 C# 记事本

vs2010 C# 记事本
(2)ToolStrip(工具栏控件)。
(3)RichTextBox(多格式文本框控件)。
(4)StatusStrip(状态栏控件)。
(5)OpenFileDialog(打开对话框)。
(6)SaveFileDialog(保存对话框)。
(7)FontDialog(字体对话框)。
(8)Timer(计时器控件)。
设置好所有的属性后,最终的用户界面如图17-2所示。到此,用户界面设计完毕,接下来介绍具体的实现过程及源代码的编写。
17.
首先在代码的通用段声明以下两个公共变量,他们都是布尔型的,“b”用于判断文件是新建的还是从磁盘打开的,“s”用于判断文件是否被保存。
//*************************************************************************
/*布尔变量b用于判断文件是新建的还是从磁盘打开的,
true表示文件是从磁盘打开的,false表示文件是新建的,默认值为false*/
bool b = false;
/*布尔变量s用于判断文件件是否被保存,
true表示文件是已经被保存了,false表示文件未被保存,默认值为true*/
bool s = true;
最终的用户界面如图17-2所示(设置好属性后),其中MenuStrip控件、ToolStrip控件、StatusStrip控件、OpenFileDialog对话框、SaveFileDialog对话框、FontDialog对话框和Timer控件显示在窗体设计器下方的组件板上。
图17-2记事本用户界面
17.
本小节将介绍窗体、菜单控件、工具栏控件、多格式文本框控件和状态栏控件的属性设置,下面首先来看一下窗体的属性设置。

C#记事本实训报告及源码

C#记事本实训报告及源码

吉林电子信息职业技术学院JiLin Technical College of Electronic Information课程实训课程名称:_________ 《C#.NET》 ___________指导教师:____________________________________ 实训时间:___________________________________吉林电子信息职业技术学院吉林电子信息职业技术学院课程实训任务书姓名:院(系):计算机系专业:软件技术班级:10软件任务起至日期:综合实训题目:“记事本”的文本编辑器已知技术参数和设计要求:应用环境:Win dows Server 2000/2003/XPSQL Server 2005开发环境:VS2005应用模式:B/S设计要求:按题目要求完成数据库设计、系统功能设计、界面设计。

(1)能够实现基本的文本文件读取、保存、设置字体等功能。

(2)具有菜单、工具栏和状态栏。

(3)实现其它相关功能(如字体、剪切板的操作,查找、打印预览等功能)(4)实现多文档界面工作量:记事本的程序测试,修改,以及添加。

工作计划安排:1项目培训、选题、准备开发环境0.5天2 项目设计、制作2天3 测试、完善0.5天4 完成报告1天同组实训者及分工:同组实训者:本人完成工作如下:记事本的代码修改以及添加测试。

指导教师签字月日年教研室主任意见:教研室主任签字年月日*注:此任务书由课程设计指导教师填写。

综合评语:成绩评定:指导教师签字 ________________________ 年教研室主任意见:教研室主任签字 _______________________系部审核盖章: 教务处批准盖章:课程实训用纸第1章问题描述(1 )能够实现基本的文本文件读取、保存、设置字体等功能。

(2) 具有菜单、工具栏和状态栏。

(3) 实现其它相关功能(如字体、剪切板的操作,查找、打印预览等功能) (4) 实现多文档界面第2章总体设计第3章界面设计1 •文件操作:包括文件的新建、打开、保存、另存为、页面设置、打印及退 出。

记事本代码

记事本代码

记事本代码#include<iostream.h>#include<string.h>#include<ctype.h> //为了以下使用isdigit(string)函数作铺垫typedef struct node{char a[100]; //每行100字符node * next; //关于此处next的作用还不清楚,但不可去掉}node;class notepad{public:notepad(){i=1;line=0;}~notepad(){}void operator_interface();void input();void ct_input();void delete1();void copy();void paste();void open();void save();char * find();void print();char store[100]; //储存需复制内容private:char * ptr_array[100]; //指针数组,记录100行行指针int linelen[100]; //最大100行int line; //当前总行数char d[30]; //记录操作数据int k,l; //记录当前查找行ilint i; //文档录入初始标记};void notepad::operator_interface(){cout<<"********************************************************"<<en dl;cout<<"***0.继续录入文档"<<endl;cout<<"***1.输入文档内容"<<endl;cout<<"***2.删除某些内容"<<endl;cout<<"***3.复制某些内容"<<endl;cout<<"***4.粘贴某些内容"<<endl;cout<<"***5.打开文档内容"<<endl;cout<<"***6.是否保存文档"<<endl;cout<<"***7.获取操作帮助"<<endl;cout<<"***8.我要结束操作"<<endl;cout<<"********************************************************"<<en dl;}void notepad::input(){-99"<<endl; cout<<"输入总行数,格式:01char e[10];cin>>e;char *lin=e;if(*(lin+2)=='\0'&&isdigit(*lin)&&isdigit(*(lin+1))){line=(*lin-'0')*10+(*(lin+1)-'0');if(line!=0){cout<<"请输入各行内容"<<endl;while(i<=line){cout<<"第"<<i<<"行 ";node *p=new node;cin>>p->a;ptr_array[i]=p->a;linelen[i]=strlen(p->a);i++;}}else cout<<"你输入的行数有误"<<endl;}else cout<<"你输入的行数有误"<<endl; }void notepad::ct_input(){if(line!=0){int i=line+1;cout<<"输入要录入的总行数,格式:01-99"<<endl;char e[10];cin>>e;char *lin=e;if(*(lin+2)=='\0'&&isdigit(*lin)&&isdigit(*(lin+1))){ line=line+(*lin-'0')*10+(*(lin+1)-'0');if(line!=0){cout<<"请输入各行内容"<<endl;while(i<=line){cout<<"第"<<i<<"行 ";node *p=new node;cin>>p->a;ptr_array[i]=p->a;linelen[i]=strlen(p->a);i++;}}else cout<<"你输入的行数有误"<<endl;}else cout<<"你输入的行数有误"<<endl;}else cout<<"当前文档并无内容,请先输入1录入文档"<<endl; }void notepad::print(){cout<<endl<<endl;int j=1;cout<<"当前文档内容为:"<<endl;while(j<=line){cout<<"第"<<j<<"行 ";char *q=ptr_array[j];while(*q!='\0'){cout<<*q;q++;}cout<<endl;j++;}cout<<endl;}char * notepad::find(){ //暂未解决跨行查找问题k=1;cin>>d;l=strlen(d);char *n=d;int c=1;char *m=ptr_array[k];while(k<=line){if(*m=='\0'){k=k+1;if(k<=line)m=ptr_array[k];}if(*m!='\0'&&*m!=*n)m++;while(*n!='\0'&&*m!='\0'&&*m==*n){ m=m+1;n=n+1;c=c+1;}if(*n=='\0'){return m-c+1;}else {n=d;c=1;}}return NULL;}void notepad::delete1(){char * dp1;char * dp2;cout<<"请输入要删除的文本前几位字符,注意区分"<<endl;dp1=find();int l1=k;cout<<"请输入要删除的文本末几位字符,注意区分"<<endl;dp2=find();int l2=k;if(dp1==NULL||dp2==NULL||l1>l2)cout<<"输入错误"<<endl;else{dp2=dp2+l;if(l1==l2){while(*dp2!='\0'){*dp1=*dp2;dp1++;dp2++;}*dp1='\0';linelen[l1]=strlen(ptr_array[l1]);}else {if(l1+1<l2){for(intt1=l1+1,t2=l2;t2<=line;t1++,t2++)ptr_array[t1]=ptr_array[t2]; line=line-l2+l1+1;l2=l1+1;}*dp1='\0';char *dp21=ptr_array[l2];while(*(dp2-1)!='\0'){*dp21=*dp2;dp21++;dp2++;}linelen[l1]=strlen(ptr_array[l1]);linelen[l2]=strlen(ptr_array[l2]);}if(linelen[l1]==0){for(int v=l1;v<=line;v++)ptr_array[v]=ptr_array[v+1]; line--;}if(linelen[l2]==0){for(int v=l2;v<=line;v++)ptr_array[v]=ptr_array[v+1]; line--;}}}void notepad::copy(){char * cp1;char * cp2;cout<<"请输入要复制的文本前几位字符,注意区分"<<endl; cp1=find();int l1=k;cout<<"请输入要复制的文本末几位字符,注意区分"<<endl; cp2=find();int l2=k;char *pt=store;if(cp1!=NULL&&cp2!=NULL&&l1<=l2){cp2=cp2+l;while(cp1!=cp2){if(*cp1=='\0'){l1++;cp1=ptr_array[l1];}else {*pt=*cp1;pt++;cp1++;}}*pt='\0';}else cout<<"输入错误"<<endl; }void notepad::paste(){cout<<"请输入要粘贴位置的前几位字符(在首字符后粘贴)"<<endl; char *pat=find();if(pat!=NULL){int choice2;cout<<"请选择要粘贴内容:1/从内存中0/我自己输入"<<endl; cin>>choice2;if(!choice2)cin>>store;char *ppt=store;for(char *pat1=pat;*(pat1+1)!='\0';pat1++); //定位至末尾int pl=strlen(store);*(pat1+pl+1)='\0';while(pat1!=pat){ //移位*(pat1+pl)=*pat1;pat1--;}pat++;for(int u=1;u<=pl;u++){*pat=*ppt;ppt++;pat++;}linelen[k]=linelen[k]+pl;}else cout<<"输入错误"<<endl;}void notepad::open(){print();}void notepad::save(){cout<<"是否保存文件,1/是0/否"<<endl;char g[10];int choice1;cin>>g;char *choi=g;if(*(choi+1)=='\0'&&isdigit(*choi)){ choice1=*choi-'0';if(choice1==1)cout<<"文件已保存"<<endl; else if(choice1==0){for(int w=1;w<=line;w++){ //相当于析构函数的作用ptr_array[w]=NULL;linelen[w]=0;}line=0;}else cout<<"输入错误"<<endl;}else cout<<"输入错误"<<endl; }void main(){cout<<"欢迎使用本程序,您可以在要输入文档内容时通过切换输入法实现输入汉字,byhk"<<endl;notepad b;b.operator_interface();char f[10];int choice;cin>>f;char *choic=f;if(*(choic+1)=='\0'&&isdigit(*choic)){ //错误输入处理机制choice=*choic-'0';}else choice=9;while(choice!=8){switch(choice){case 0:b.ct_input();break;case 1:b.input();break;case 2:b.delete1();b.print();break;case 3:{b.copy();cout<<endl;char *p_t=b.store;int fzcd=strlen(b.store);cout<<"你所要复制的内容长度为"<<endl<<fzcd<<endl; cout<<"你所要复制的内容为"<<endl;while(*p_t!='\0'){cout<<*p_t;p_t++;}cout<<endl;}break;case 4:b.paste();b.print();break;case 5:b.open();break;case 6:b.save();break;case 7:b.operator_interface();break;case 8:break;default:break;}if(choice==9||(choice>=0&&choice<=7)){ //输入错误时的操作及输入正确时 //的继续操作判断if(choice==9)cout<<"你输入的操作有误,请重新输入,输入 7 获取操作帮助"<<endl;else cout<<"继续你的操作,输入 7 获取操作帮助"<<endl;cin>>f;choic=f;if(*(choic+1)=='\0'&&isdigit(*choic)) //错误输入处理机制choice=*choic-'0';else choice=9;}}cout<<"感谢您的使用"<<endl; }。

记事本源码

记事本源码
'浏览器
Private Sub Command1_Click()
Web1.Navigate2 Url.text
End Sub
Private Sub Command10_Click()
Web2.Navigate2 ""
End Sub
Private Sub Command7_Click()
Txt.FontItalic = Common.FontItalic
Txt.FontName = Common.FontName
Txt.FontSize = Common.FontSize
End Sub
Private Sub Form_Load()
'初始化StatusBar1中的时间显示
Loop
text = st
Txt.text = text
End Sub
'删除所有行首空格
Private Sub DelSK_Click()
Dim text As String, s As String, i As Integer, j As Integer
text = Txt.text
ZhanTie.Enabled = True
End Sub
'删除选中的文本
Private Sub Delect_Click()
Txt.SelText = ""
End Sub
'删除全部空行
Private Sub DelKH_Click()
Dim text As String, s As String, st As String

记事本VS2013 C#源程序

记事本VS2013   C#源程序

C#记事本源程序(VS2013)图1 程序设计界面程序源代码:using System;using System.Collections.Generic;using ponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.IO;using System.Windows.Forms;namespace 记事本{public partial class FormMain : Form{/// <summary>/// 判断是否需要保存/// </summary>private bool needToSave;/// <summary>/// 记录单前文件的路径及名字/// </summary>private string currentFileName = null;/// <summary>/// 记录打开的内容/// </summary>private string initText;/// <summary>/// 设置文本缩进的序号/// </summary>private int index=0;int start, end, location, erorr = 0;private System.Drawing.Printing.PrintDocument printDocument = newSystem.Drawing.Printing.PrintDocument();public FormMain(){InitializeComponent();}private void menuStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e) {}private void ToolStripMenuItemNew_Click(object sender, EventArgs e){checkChange();if (needToSave == true){DialogResult result = MessageBox.Show("文本内容已改变需要保存吗?", "保存文件", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);switch (result){case DialogResult.Yes:{ToolStripMenuItemSave_Click(sender, e);textBoxEdit.Clear();this.Text = "文本编辑--新建文本";break;}case DialogResult.No:{textBoxEdit.Clear();this.Text = "文本编辑--新建文本";break;}case DialogResult.Cancel:{break;}}}else{textBoxEdit.Clear();this.Text = "文本编辑新建文本";}initText = textBoxEdit.Text;currentFileName = null;}private void ToolStripMenuItemSave_Click(object sender, EventArgs e){if (currentFileName == null){ToolStripMenuItemSaveAs_Click(sender, e);}else{saveFile(textBoxEdit.Text);initText = textBoxEdit.Text;}}private void ToolStripMenuItemOpen_Click(object sender, EventArgs e){checkChange();if (needToSave == true){DialogResult result = MessageBox.Show("文本内容已改变,是否保存?", "保存文件", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);if (result == DialogResult.Cancel){return;}if (result == DialogResult.Yes){ToolStripMenuItemSave_Click(sender, e);}}string file = GetOpenFile();if (file == null){return;}else{currentFileName = file;openFile();initText = textBoxEdit.Text;}}/// <summary>/// 打开文本文件/// </summary>private void openFile(){try{FileInfo f = new FileInfo(currentFileName);StreamReader reader = new StreamReader(currentFileName,System.Text.Encoding.Default);textBoxEdit.Text = reader.ReadToEnd();reader.Close();this.Text = "文本编辑--" + ;}catch (Exception e){MessageBox.Show(e.Message);}}/// <summary>/// 获得打开的文件的路径/// </summary>private string GetOpenFile(){OpenFileDialog openFile = new OpenFileDialog();openFile.Title = "打开本地文件";openFile.CheckFileExists = true;openFile.CheckPathExists = true;openFile.AddExtension = true;openFile.Multiselect = false;openFile.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";if (openFile.ShowDialog() == DialogResult.OK){return openFile.FileName;}else{return null;}}/// <summary>/// 文件保存/// </summary>/// <param name="str"></param>private void saveFile(string str){try{StreamWriter writer = new StreamWriter(currentFileName, false, System.Text.Encoding.Default);writer.Write(str);writer.Close();}catch (Exception e){MessageBox.Show(e.Message);}}private void FormMain_Load(object sender, EventArgs e){initText = textBoxEdit.Text;//判断剪切板里面有没有数据从而初始化按钮可用不可用DataFormats.Format textFormat = DataFormats.GetFormat(DataFormats.Text); if (textBoxEdit.CanPaste(textFormat)){ToolStripMenuItemUndo.Enabled = false;ToolStripMenuItemCut.Enabled = false;ToolStripMenuItemCopy.Enabled = false;ToolStripMenuItemFind.Enabled = false;ToolStripMenuItemReplace.Enabled = false;ToolStripMenuItemDelete.Enabled = false;ToolStripMenuItemSelectAll.Enabled = false;btnBack.Enabled = false;btnCopy.Enabled = false;btnCut.Enabled = false;btnSearch.Enabled = false;}else{ToolStripMenuItemUndo.Enabled = false;ToolStripMenuItemCut.Enabled = false;ToolStripMenuItemCopy.Enabled = false;ToolStripMenuItemFind.Enabled = false;ToolStripMenuItemReplace.Enabled = false;ToolStripMenuItemDelete.Enabled = false;ToolStripMenuItemSelectAll.Enabled = false;ToolStripMenuItemPaste.Enabled = false;btnBack.Enabled = false;btnCopy.Enabled = false;btnCut.Enabled = false;btnPaste.Enabled = false;btnSearch.Enabled = false;}}/// <summary>/// 获得要保存的文件/// </summary>/// <returns></returns>private string getSaveFile(){SaveFileDialog saveFile = new SaveFileDialog();saveFile.Title = "保存文本文件";saveFile.OverwritePrompt = true;saveFile.CreatePrompt = true;saveFile.AddExtension = true;saveFile.Filter = "文本文件(*.txt)|*.txt|所有文件(*.*)|*.*";if (saveFile.ShowDialog() == DialogResult.OK){return saveFile.FileName;}else{return null;}}/// <summary>/// 判断是否改变/// </summary>private void checkChange(){if (initText == textBoxEdit.Text){needToSave = false;}else{needToSave = true;}}private void ToolStripMenuItemSaveAs_Click(object sender, EventArgs e) {string file = getSaveFile();if (file == null){return;}else{currentFileName = file;saveFile(textBoxEdit.Text);FileInfo f = new FileInfo(currentFileName);this.Text = "文本编辑--" + ;initText = textBoxEdit.Text;}}private void ToolStripMenuItemPageSet_Click(object sender, EventArgs e) {PageSetupDialog pageSet = new PageSetupDialog();pageSet.Document = printDocument;pageSet.ShowDialog();}private void ToolStripMenuItemPrint_Click(object sender, EventArgs e) {PrintDialog printDialog = new PrintDialog();printDialog.Document = printDocument;if (printDialog.ShowDialog() == DialogResult.OK){try{printDocument.Print();}catch (Exception e1){MessageBox.Show(e1.Message);}}}private void ToolStripMenuItemExit_Click(object sender, EventArgs e){this.Close();}private void ToolStripMenuItemUndo_Click(object sender, EventArgs e){//如果可以进行撤消则进行撤消操作if (textBoxEdit.CanUndo == true){textBoxEdit.Undo();}}private void ToolStripMenuItemCut_Click(object sender, EventArgs e){//如果选中的内容不为空则进行剪切,同时复制和删除可用if (textBoxEdit.SelectedText != ""){textBoxEdit.Cut();ToolStripMenuItemCopy.Enabled = true;ToolStripMenuItemDelete.Enabled = true;}}private void ToolStripMenuItemCopy_Click(object sender, EventArgs e){//如果选中的内容长度大于0则可以进行复制if (textBoxEdit.SelectionLength > 0){textBoxEdit.Copy();}}private void ToolStripMenuItemPaste_Click(object sender, EventArgs e){//粘贴功能如果可以进行将系统剪切板的内容转换为Text格式的则进行粘贴if (Clipboard.GetDataObject().GetDataPresent(DataFormats.Text) == true) {//判断是否有被选中的内容如果有的话则询问是否要进行替换。

记事本程序源代码汇总

记事本程序源代码汇总

import java.awt.event.*;import java.awt.*;import java.io.*;import ng.String;class jsb implements ActionListener{Dialog bb;String strt;int i;FileDialog fd;File file;public Frame f;public TextArea p1;public MenuBar menubar;public Menu menu1,menu2,menu3;public MenuItem item1,item2,item3,item4,item5,item6,item7,item8,item9,item10; jsb(String s{ i=0;f=new Frame(s;p1=new TextArea("";f.setSize(500,500;f.setBackground(Color.white;f.setVisible(true;menubar=new MenuBar(;menu1=new Menu("文件";menu2=new Menu("编辑";menu3=new Menu("帮助";item1=new MenuItem("新建";item2=new MenuItem("打开";item3=new MenuItem("保存";item4=new MenuItem("另存为";item5=new MenuItem("退出";item6=new MenuItem("全选";item7=new MenuItem("复制";item8=new MenuItem("剪切";item9=new MenuItem("粘贴";item10=new MenuItem("关于";f.addWindowListener(new WindowAdapter({public void windowClosing(WindowEvent e {f.setVisible(false;System.exit(0;}};menu1.add(item1;menu1.add(item2;menu1.add(item3;menu1.add(item4;menu1.add(item5;menu2.add(item6;menu2.add(item7;menu2.add(item8;menu2.add(item9;menu3.add(item10;menubar.add(menu1;menubar.add(menu2;menubar.add(menu3;f.setMenuBar(menubar;item1.addActionListener(this;item2.addActionListener(this;item3.addActionListener(this;item4.addActionListener(this;item5.addActionListener(this;item6.addActionListener(this;item7.addActionListener(this;item8.addActionListener(this;item9.addActionListener(this;item10.addActionListener(this;f.setLayout(new GridLayout(1,1;f.add(p1;f.pack(;}public void actionPerformed(ActionEvent e { String ss;ss=p1.getText(.trim(;if (e.getSource(==item5{if (i==0 &&(ss.length(!=0{bc(;}else{System.exit(0;}}if (e.getSource(==item1{if (i==0&&(ss.length(!=0{bc(;}else{p1.setText("";i=0;f.setTitle("文件对话框"; } }if (e.getSource(==item2{fd=new FileDialog(f,"打开文件",0;fd.setVisible(true;try{file=new File(fd.getDirectory(,fd.getFile(;f.setTitle(fd.getFile(+"文件对话框"; FileReader fr=new FileReader(file; BufferedReader br=new BufferedReader(fr; String line = null;String view = "";while((line=br.readLine(!=null{view += line+"\n";}p1.setText(view;br.close(;fr.close(;}catch(IOException expIn{}}if (e.getSource(==item3{if (i==0{bc(;}else{try{file=new File(fd.getDirectory(,fd.getFile(;f.setTitle(fd.getFile(+"--记事本";FileWriter fw=new FileWriter(file; BufferedWriter bw=new BufferedWriter(fw; String s =p1.getText(;s = s.replaceAll("\n","\r\n";bw.write(s;bw.flush(;bw.close(;fw.close(;i=1;}catch(IOException expOut{i=0;}}}if (e.getSource(==item4{bc(;}if (e.getSource(==item10{bb=new Dialog(f,"关于";Label l1=new Label("本记事本的完成感谢老师和同学的帮助!!"; bb.add(l1; bb.setSize(250,150;bb.setBackground(Color.white;bb.show(;bb.addWindowListener(new WindowAdapter({public void windowClosing(WindowEvent e{bb.setVisible(false;bb.dispose(;}};}if (e.getSource(==item6{p1.setSelectionStart(0;p1.setSelectionEnd(p1.getText(.length(; }if (e.getSource(==item7{try{String str=p1.getSelectedText(;if(str.length(!=0{strt=str;}}catch(Exception ex{}}if (e.getSource(==item8{try{String str=p1.getSelectedText(;if(str.length(!=0{p1.replaceRange("",p1.getSelectionStart(,p1.getSelectionEnd(; } }catch(Exception ex{}}if (e.getSource(==item9{if(strt.length(>0{p1.insert(strt,p1.getCaretPosition(;}}}public void bc({fd=new FileDialog(f,"保存文件",1;fd.setVisible(true;try{file=new File(fd.getDirectory(,fd.getFile(;f.setTitle(fd.getFile(+"--记事本"; FileWriter fw=new FileWriter(file; BufferedWriter bw=new BufferedWriter(fw; String s =p1.getText(;s = s.replaceAll("\n","\r\n";bw.write(s;bw.flush(;bw.close(;fw.close(;i=1;}catch(IOException expOut{}} } public class EX0101 { public static void main(String args[] {jsb dd=new jsb("我的记事本";} }。

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

记事本一、打开visual studio 新建——项目——windows窗体应用程序命名:年终大作业;二、Form.cs中作如下操作:三、在工具箱中选择如下控件:menuStrip、contextMenustrip、colordialog、savefiledialog、folderbrowserdialog、fontdialog、openfiledialog、statustrip 、Folderbrowserdialog四、单击menuStrip并输入文件(&F),双击后输入新建(&N)并单击新建在属性中的shortkeys中选择Ctl+N;并在那么属性中改名为“新建”、后面类似;五、单击statustrip在其属性中的item属性中选择添加label4个;六、分别输入以下代码:using System;七、using System.Collections.Generic;八、using ponentModel;九、using System.Data;十、using System.Drawing;十一、using System.Linq;十二、using System.Text;十三、using System.Windows.Forms;十四、using System.IO;十五、十六、十七、namespace 年终大作业十八、{十九、public partial class Form1 : Form二十、{二十一、public Form1()二十二、{二十三、InitializeComponent();二十四、}二十五、二十六、private void 新建_Click(object sender, EventArgs e)二十七、{二十八、this.richTextBox1.Text="";二十九、}三十、三十一、private void 打开_Click(object sender, EventArgs e)三十二、{三十三、openFileDialog1.FileName = "";三十四、openFileDialog1.Filter = "RTF File(*.rtf)|*.RTF|TXT FILE(*.txt)|*.txt";三十五、openFileDialog1.ShowDialog();三十六、if (openFileDialog1.FileName != "")三十七、switch (openFileDialog1.FilterIndex)三十八、{三十九、case 1: //选择的是.rtf类型四十、richTextBox1.LoadFile(openFileDialog1.FileName,RichTextBoxStreamType.RichText);四十一、break;四十二、case 2: //选择的是.txt类型四十三、richTextBox1.LoadFile(openFileDialog1.FileName,RichTextBoxStreamType.PlainText);四十四、break;四十五、}四十六、}四十七、四十八、private void 保存_Click(object sender, EventArgs e)四十九、{五十、saveFileDialog1.Filter = "RTF File(*.rtf)|*.RTF|TXT FILE(*.txt)|*.txt";五十一、if (saveFileDialog1.ShowDialog() == DialogResult.OK) 五十二、switch (openFileDialog1.FilterIndex)五十三、{五十四、case 1: //选择的是.rtf类型五十五、richTextBox1.SaveFile(saveFileDialog1.FileName,RichTextBoxStreamType.RichText);五十六、break;五十七、case 2: //选择的是.txt类型五十八、richTextBox1.SaveFile(saveFileDialog1.FileName,RichTextBoxStreamType.PlainText);五十九、break;六十、}六十一、}六十二、六十三、private void 另存为_Click(object sender, EventArgs e)六十四、{六十五、saveFileDialog1.Filter = "RTF File(*.rtf)|*.RTF|TXT FILE(*.txt)|*.txt";六十六、if (saveFileDialog1.ShowDialog() == DialogResult.OK) 六十七、switch (openFileDialog1.FilterIndex)六十八、{六十九、case 1: //选择的是.rtf类型七十、richTextBox1.SaveFile(saveFileDialog1.FileName,RichTextBoxStreamType.RichText);七十一、break;七十二、case 2: //选择的是.txt类型七十三、richTextBox1.SaveFile(saveFileDialog1.FileName,RichTextBoxStreamType.PlainText);七十四、break;七十五、}七十六、}七十七、七十八、private void 退出_Click(object sender, EventArgs e)七十九、{八十、// 退出时应提示用户是否保存当前文本文件八十一、DialogResult result = MessageBox.Show("是否将更改保存?", "Mickey温馨提示", MessageBoxButtons.YesNoCancel,rmation);八十二、if (result == DialogResult.Yes)八十三、{八十四、saveFileDialog1.Filter = "RTF File(*.rtf)|*.RTF|TXT FILE(*.txt)|*.txt";八十五、if (saveFileDialog1.ShowDialog() == DialogResult.OK)八十六、switch (openFileDialog1.FilterIndex) 八十七、{八十八、case 1: //选择的是.rtf类型八十九、richTextBox1.SaveFile(saveFileDialog1.FileName,RichTextBoxStreamType.RichText);九十、break;九十一、case 2: //选择的是.txt类型九十二、richTextBox1.SaveFile(saveFileDialog1.FileName,RichTextBoxStreamType.PlainText);九十三、break;九十四、}九十五、Application.Exit();九十六、this.Close();九十七、}九十八、else if (result == DialogResult.No)九十九、{百、Application.Exit();百一、}百二、}百三、百四、private void 撤销_Click(object sender, EventArgs e) 百五、{百六、richTextBox1.Undo();百七、}百八、百九、private void 剪切_Click(object sender, EventArgs e)百十、{百十一、richTextBox1.Cut();百十二、}百十三、百十四、private void 复制_Click(object sender, EventArgs e)百十五、{百十六、richTextBox1.Copy();百十七、}百十八、百十九、private void 粘贴_Click(object sender, EventArgs e)百二十、{百二十一、richTextBox1.Paste();百二十二、}百二十三、百二十四、private void 删除_Click(object sender, EventArgs e)百二十五、{百二十六、richTextBox1.Clear();百二十七、}百二十八、百二十九、private void 全选_Click(object sender, EventArgs e)百三十、{百三十一、richTextBox1.SelectAll();百三十二、}百三十三、百三十四、private void 时间日期_Click(object sender, EventArgs e) 百三十五、{百三十六、richTextBox1.SelectedText =System.DateTime.Now.ToLocalTime().ToString();百三十七、}百三十八、百三十九、private void 自动换行_Click(object sender, EventArgs e) 百四十、{百四十一、if (richTextBox1.WordWrap == true)百四十二、{百四十三、自动换行.Checked = true;百四十四、richTextBox1.WordWrap = false;百四十五、百四十六、}百四十七、else百四十八、{百四十九、自动换行.Checked = false;百五十、richTextBox1.WordWrap = true;百五十一、}百五十二、}百五十三、百五十四、private void 背景颜色_Click(object sender, EventArgs e) 百五十五、{百五十六、colorDialog1.ShowDialog();百五十七、richTextBox1.BackColor = colorDialog1.Color;百五十八、}百五十九、百六十、private void 状态栏_Click(object sender, EventArgs e) 百六十一、{百六十二、if (statusStrip1.Visible == true)百六十三、{百六十四、状态栏.Checked = false;百六十五、statusStrip1.Visible = false;百六十六、}百六十七、else百六十八、{百六十九、状态栏.Checked = true;百七十、statusStrip1.Visible = true;百七十一、}百七十二、}百七十三、百七十四、private void 右撤销_Click(object sender, EventArgs e) 百七十五、{百七十六、richTextBox1.Undo();百七十七、}百七十八、百七十九、private void 右剪切_Click(object sender, EventArgs e)百八十、{百八十一、richTextBox1.Cut();百八十二、}百八十三、百八十四、private void 右复制_Click(object sender, EventArgs e)百八十五、{百八十六、richTextBox1.Copy();百八十七、}百八十八、百八十九、private void 右粘贴_Click(object sender, EventArgs e)百九十、{百九十一、richTextBox1.Paste();百九十二、}百九十三、百九十四、private void 右删除_Click(object sender, EventArgs e)百九十五、{百九十六、richTextBox1.Clear();百九十七、}百九十八、百九十九、private void 右全选_Click(object sender, EventArgs e)二百、{二百一、richTextBox1.SelectAll();二百二、}二百三、二百四、private void 字体颜色_Click_1(object sender, EventArgse)二百五、{二百六、fontDialog1.AllowVectorFonts = true;//设置用户可以选择矢量字体二百七、fontDialog1.AllowVerticalFonts = true;//设置字体对话框既显示水平字体,也显示垂直字体二百八、fontDialog1.FixedPitchOnly = false;//设置用户可以选择不固定间距的字体二百九、fontDialog1.MaxSize = 72;//设置可选择的最大字二百十、fontDialog1.MinSize = 5;//设置可选择的最小字二百十一、if (fontDialog1.ShowDialog() == DialogResult.OK)//判断是否选择了字体二百十二、{二百十三、if (richTextBox1.SelectedText == "")//判断是否选择了文本二百十四、richTextBox1.SelectAll();//全选文本二百十五、richTextBox1.SelectionFont = fontDialog1.Font;//设置选中的文本字体二百十六、}二百十七、colorDialog1.AllowFullOpen = true;//设置允许用户自定义颜色二百十八、colorDialog1.AnyColor = true;//设置颜色对话框中显示所有颜色二百十九、colorDialog1.SolidColorOnly = false;//设置用户可以在颜色对话框中选择复杂颜色二百二十、if (colorDialog1.ShowDialog() == DialogResult.OK)//判断是否选择了颜色二百二十一、{二百二十二、if (richTextBox1.SelectedText == "")//判断是否选择了文本二百二十三、richTextBox1.SelectAll();//全选文本二百二十四、richTextBox1.SelectionColor = colorDialog1.Color;//将选定的文本颜色设置为颜色对话框中选择的颜色二百二十五、}二百二十六、二百二十七、}二百二十八、二百二十九、private void Form1_FormClosed(object sender, FormClosedEventArgs e)二百三十、{二百三十一、// 退出时应提示用户是否保存当前文本文件二百三十二、DialogResult result = MessageBox.Show("是否将更改保存?", "Mickey温馨提示", MessageBoxButtons.YesNoCancel,rmation);二百三十三、if (result == DialogResult.Yes)二百三十四、{二百三十五、saveFileDialog1.Filter = "RTFFile(*.rtf)|*.RTF|TXT FILE(*.txt)|*.txt";二百三十六、if (saveFileDialog1.ShowDialog() == DialogResult.OK)二百三十七、switch (openFileDialog1.FilterIndex)二百三十八、{二百三十九、case 1: //选择的是.rtf类型二百四十、richTextBox1.SaveFile(saveFileDialog1.FileName,RichTextBoxStreamType.RichText);二百四十一、break;二百四十二、case 2: //选择的是.txt类型二百四十三、richTextBox1.SaveFile(saveFileDialog1.FileName,RichTextBoxStreamType.PlainText);二百四十四、break;二百四十五、}二百四十六、Application.Exit();二百四十七、}二百四十八、MessageBox.Show("谢谢使用!"+DateTime.Now );二百四十九、}二百五十、二百五十一、private void 关于主题_Click(object sender, EventArgse)二百五十二、{二百五十三、主题();二百五十四、}二百五十五、private void 主题()二百五十六、{二百五十七、string str = "本程序由本人初次制作,内容可能还有些许漏洞,如果在您使用过程中发现问题,敬请联系本人。

相关文档
最新文档