VS编写的记事本源码
记事本(代码)
char t; //选择是否继续输入
flag:
printf("请输入第%d个学生信息\n",a+1);
printf("学号:");
scanf("%d",>[a].xuehao);
printf("姓名:");
scanf("%s",>[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# 记事本
(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#记事本实训报告及源码
吉林电子信息职业技术学院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#源程序
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("我的记事本";} }。
使用Windows自带的记事本编写简单代码
使用Windows自带的记事本编写简单代码在如今数字化的时代,编程不再是专业程序员的专属技能,普通人也可以通过简单的工具和基础的知识来体验编程的乐趣。
Windows 自带的记事本就是这样一个容易上手的工具,它虽然看似简单,但却能帮助我们编写一些简单的代码。
首先,让我们来了解一下记事本。
记事本是 Windows 操作系统中一个基本的文本编辑工具,它没有复杂的功能和花哨的界面,只有纯粹的文字编辑区域。
但这恰恰为我们编写代码提供了一个干净、简洁的环境。
当我们决定使用记事本编写代码时,第一步就是打开它。
在Windows 系统中,您可以通过点击“开始”菜单,然后在搜索框中输入“记事本”来找到并打开它。
或者,您也可以按下快捷键“Windows +R”,在弹出的“运行”对话框中输入“notepad”并回车。
接下来,让我们从一个简单的 HTML 代码开始入手。
HTML(超文本标记语言)是用于创建网页的基础语言。
以下是一个简单的 HTML代码示例,用于创建一个包含标题和段落的网页:```html<!DOCTYPE html><html><head><title>我的第一个网页</title></head><body><h1>这是一个标题</h1><p>这是一个段落。
</p></body></html>```在记事本中输入上述代码后,点击“文件”菜单,选择“另存为”。
在“文件名”框中,输入“my_first_webpagehtml”(注意,一定要加上“html”扩展名,否则浏览器无法正确识别它为 HTML 文件),然后选择保存类型为“所有文件”,最后选择一个您想要保存的位置,点击“保存”。
保存完成后,找到您保存的文件,双击它,它应该会在您的默认浏览器中打开,显示出您刚刚编写的网页内容,包含一个标题和一个段落。
除了 HTML,我们还可以使用记事本编写 Python 代码。
Java记事本源代码(完整)
/*** 作品:记事本* 作者:**** 功能:简单的文字编辑*/import java.awt.*;import java.awt.event.*;import java.io.*;import javax.swing.*;import javax.swing.event.ChangeEvent;import javax.swing.event.ChangeListener;class NotePad extends JFrame{private JMenuBar menuBar;private JMenu fielMenu,editMenu,formMenu,aboutMenu;private JMenuItemnewMenuItem,openMenuItem,saveMenuItem,exitMenuItem;private JMenuItemcutMenuItem,copyMenuItem,pasteMenuItem,foundItem,replaceItem,s electAll;private JMenuItem font,about;private JTextArea textArea;private JFrame foundFrame,replaceFrame;private JCheckBoxMenuItem wrapline;private JTextField textField1=new JTextField(15);private JTextField textField2=new JTextField(15);private JButton startButton,replaceButton,reallButton;int start=0;String value;File file=null;JFileChooser fileChooser=new JFileChooser();boolean wrap=false;public NotePad(){//创建文本域textArea=new JTextArea();add(new JScrollPane(textArea),BorderLayout.CENTER);//创建文件菜单及文件菜单项fielMenu=new JMenu("文件");fielMenu.setFont(new Font("微软雅黑",0,15));newMenuItem=new JMenuItem("新建",newImageIcon("icons\\new24.gif"));newMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));newMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent. VK_N,InputEvent.CTRL_MASK));newMenuItem.addActionListener(listener);openMenuItem=new JMenuItem("打开",newImageIcon("icons\\open24.gif"));openMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));openMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent .VK_O,InputEvent.CTRL_MASK));openMenuItem.addActionListener(listener);saveMenuItem=new JMenuItem("保存",newImageIcon("icons\\save.gif"));saveMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));saveMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent .VK_S,InputEvent.CTRL_MASK));saveMenuItem.addActionListener(listener);exitMenuItem=new JMenuItem("退出",newImageIcon("icons\\exit24.gif"));exitMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));exitMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent .VK_E,InputEvent.CTRL_MASK));exitMenuItem.addActionListener(listener);//创建编辑菜单及菜单项editMenu=new JMenu("编辑");editMenu.setFont(new Font("微软雅黑",0,15));cutMenuItem=new JMenuItem("剪切",newImageIcon("icons\\cut24.gif"));cutMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent. VK_X,InputEvent.CTRL_MASK));cutMenuItem.addActionListener(listener);copyMenuItem=new JMenuItem("复制",newImageIcon("icons\\copy24.gif"));copyMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent .VK_C,InputEvent.CTRL_MASK));copyMenuItem.addActionListener(listener);pasteMenuItem=new JMenuItem("粘贴",newImageIcon("icons\\paste24.gif"));pasteMenuItem.setFont(new Font("微软雅黑",Font.BOLD,13));pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEven t.VK_V,InputEvent.CTRL_MASK));pasteMenuItem.addActionListener(listener);foundItem=new JMenuItem("查找");foundItem.setFont(new Font("微软雅黑",Font.BOLD,13));foundItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK _F,InputEvent.CTRL_MASK));foundItem.addActionListener(listener);replaceItem=new JMenuItem("替换");replaceItem.setFont(new Font("微软雅黑",Font.BOLD,13));replaceItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent. VK_R,InputEvent.CTRL_MASK));replaceItem.addActionListener(listener);selectAll=new JMenuItem("全选");selectAll.setFont(new Font("微软雅黑",Font.BOLD,13));selectAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK _A,InputEvent.CTRL_MASK));selectAll.addActionListener(listener);//创建格式菜单及菜单项formMenu=new JMenu("格式");formMenu.setFont(new Font("微软雅黑",0,15));wrapline=new JCheckBoxMenuItem("自动换行");wrapline.setFont(new Font("微软雅黑",Font.BOLD,13));wrapline.addActionListener(listener);wrapline.addChangeListener(new ChangeListener() {public void stateChanged(ChangeEvent e) {if(wrapline.isSelected()){textArea.setLineWrap(true);}elsetextArea.setLineWrap(false);}});font=new JMenuItem("字体");font.setFont(new Font("微软雅黑",Font.BOLD,13)); font.addActionListener(listener);//创建关于菜单aboutMenu=new JMenu("关于");aboutMenu.setFont(new Font("微软雅黑",0,15)); about=new JMenuItem("记事本……");about.setFont(new Font("微软雅黑",Font.BOLD,13)); about.addActionListener(listener);//添加文件菜单项fielMenu.add(newMenuItem);fielMenu.add(openMenuItem);fielMenu.add(saveMenuItem);fielMenu.addSeparator();fielMenu.add(exitMenuItem);//添加编辑菜单项editMenu.add(cutMenuItem);editMenu.add(copyMenuItem);editMenu.add(pasteMenuItem);editMenu.add(foundItem);editMenu.add(replaceItem);editMenu.addSeparator();editMenu.add(selectAll);//添加格式菜单项formMenu.add(wrapline);formMenu.add(font);//添加关于菜单项aboutMenu.add(about);//添加菜单menuBar=new JMenuBar();menuBar.add(fielMenu);menuBar.add(editMenu);menuBar.add(formMenu);menuBar.add(aboutMenu);setJMenuBar(menuBar);//创建两个框架,用作查找和替换foundFrame=new JFrame();replaceFrame=new JFrame();//创建两个文本框textField1=new JTextField(15);textField2=new JTextField(15);startButton=new JButton("开始");startButton.addActionListener(listener);replaceButton=new JButton("替换为");replaceButton.addActionListener(listener);reallButton=new JButton("全部替换");reallButton.addActionListener(listener);}//创建菜单项事件监听器ActionListener listener=new ActionListener() {public void actionPerformed(ActionEvent e) {String name=e.getActionCommand();if(e.getSource() instanceof JMenuItem){if("新建".equals(name)){textArea.setText("");file=null;}if("打开".equals(name)){if(file!=null){fileChooser.setSelectedFile(file);}intreturnVal=fileChooser.showOpenDialog(NotePad.this);if(returnVal==JFileChooser.APPROVE_OPTION){file=fileChooser.getSelectedFile();}try{FileReader reader=new FileReader(file);int len=(int)file.length();char[] array=new char[len];reader.read(array,0,len);reader.close();textArea.setText(new String(array));}catch(Exception e_open){e_open.printStackTrace();}}}if("保存".equals(name)){if(file!=null){fileChooser.setSelectedFile(file);}intreturnVal=fileChooser.showSaveDialog(NotePad.this);if(returnVal==JFileChooser.APPROVE_OPTION){file=fileChooser.getSelectedFile();}try{FileWriter writer=new FileWriter(file);writer.write(textArea.getText());writer.close();}catch (Exception e_save) {e_save.getStackTrace();}}if("退出".equals(name)){System.exit(0);}if("剪切".equals(name)){textArea.cut();}if("复制".equals(name)){textArea.copy();}if("粘贴".equals(name)){textArea.paste();}if("查找".equals(name)){value=textArea.getText();foundFrame.add(textField1,BorderLayout.CENTER);foundFrame.add(startButton,BorderLayout.SOUTH);foundFrame.setLocation(300,300);foundFrame.setTitle("查找");foundFrame.pack();foundFrame.setVisible(true);foundFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE );}if("替换".equals(name)){value=textArea.getText();JLabel label1=new JLabel("查找内容:");JLabel label2=new JLabel("替换为:");JPanel panel1=new JPanel();panel1.setLayout(new GridLayout(2,2));JPanel panel2=new JPanel();panel2.setLayout(new GridLayout(1,3));replaceFrame.add(panel1,BorderLayout.NORTH);replaceFrame.add(panel2,BorderLayout.CENTER);panel1.add(label1);panel1.add(textField1);panel1.add(label2);panel1.add(textField2);panel2.add(startButton);panel2.add(replaceButton);panel2.add(reallButton);replaceFrame.setTitle("替换");replaceFrame.setLocation(300,300);replaceFrame.pack();replaceFrame.setVisible(true);replaceFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLO SE);}if("开始".equals(name)||"下一个".equals(name)){String temp=textField1.getText();int s=value.indexOf(temp,start);if(value.indexOf(temp,start)!=-1){textArea.setSelectionStart(s);textArea.setSelectionEnd(s+temp.length());textArea.setSelectedTextColor(Color.GREEN);start=s+1;startButton.setText("下一个");}else {JOptionPane.showMessageDialog(foundFrame, "查找完毕!", "提示", 0,new ImageIcon("icons\\search.gif"));foundFrame.dispose();}}if("替换为".equals(name)){String temp=textField1.getText();int s=value.indexOf(temp,start);if(value.indexOf(temp,start)!=-1){textArea.setSelectionStart(s);textArea.setSelectionEnd(s+temp.length());textArea.setSelectedTextColor(Color.GREEN);start=s+1;textArea.replaceSelection(textField2.getText());}else {JOptionPane.showMessageDialog(foundFrame, "查找完毕!", "提示", 0,new ImageIcon("icons\\search.gif"));foundFrame.dispose();}}if("全部替换".equals(name)){String temp=textArea.getText();temp=temp.replaceAll(textField1.getText(),textField2.getTex t());textArea.setText(temp);}if("全选".equals(name)){textArea.selectAll();}if("字体".equals(name)){FontDialog fontDialog=newFontDialog(NotePad.this);fontDialog.setVisible(true);if(textArea.getFont()!=fontDialog.getFont()){textArea.setFont(fontDialog.getFont());}}if("记事本……".equals(name)){AboutDialog aboutDialog=newAboutDialog(NotePad.this);aboutDialog.setVisible(true);}}};//创建字体设置对话面板,并添加相应事件监听器class FontDialog extends JDialog implements ItemListener, ActionListener, WindowListener{public JCheckBox Bold=new JCheckBox("Bold",false);public JCheckBox Italic=new JCheckBox("Italic",false);public List Size,Name;public int FontName;public int FontStyle;public int FontSize;public JButton OK=new JButton("OK");public JButton Cancel=new JButton("Cancel");public JTextArea Text=new JTextArea("字体预览文本域\n0123456789\nAaBbCcXxYyZz");public FontDialog(JFrame owner) {super(owner,"字体设置",true);GraphicsEnvironmentg=GraphicsEnvironment.getLocalGraphicsEnvironment();String name[]=g.getAvailableFontFamilyNames();Name=new List();Size=new List();FontName=0;FontStyle=0;FontSize=8;int i=0;Name.add("Default Value");for(i=0;i<name.length;i++)Name.add(name[i]);for(i=8;i<257;i++)Size.add(String.valueOf(i));this.setLayout(null);this.setBounds(250,200,480, 306);this.setResizable(false);OK.setFocusable(false);Cancel.setFocusable(false);Bold.setFocusable(false);Italic.setFocusable(false);Name.setFocusable(false);Size.setFocusable(false);Name.setBounds(10, 10, 212, 259);this.add(Name);Bold.setBounds(314, 10, 64, 22);this.add(Bold);Italic.setBounds(388, 10, 64, 22);this.add(Italic);Size.setBounds(232, 10, 64, 259);this.add(Size);Text.setBounds(306, 40, 157, 157);this.add(Text);OK.setBounds(306, 243, 74, 26);this.add(OK);Cancel.setBounds(390, 243, 74, 26);this.add(Cancel);Name.select(FontName);Size.select(FontSize);Text.setFont(getFont());Name.addItemListener(this);Size.addItemListener(this);Bold.addItemListener(this);Italic.addItemListener(this);OK.addActionListener(this);Cancel.addActionListener(this);this.addWindowListener(this);}public void itemStateChanged(ItemEvent e) {Text.setFont(getFont());}public void actionPerformed(ActionEvent e) {if(e.getSource()==OK){FontName=Name.getSelectedIndex();FontStyle=getStyle();FontSize=Size.getSelectedIndex();this.setVisible(false);}else cancel();}public void windowClosing(WindowEvent e) {cancel();}public Font getFont(){if(Name.getSelectedIndex()==0) return new Font("新宋体",getStyle(),Size.getSelectedIndex()+8);else return newFont(Name.getSelectedItem(),getStyle(),Size.getSelectedIndex() +8);}public void cancel(){Name.select(FontName);Size.select(FontSize);setStyle();Text.setFont(getFont());this.setVisible(false);}public void setStyle(){if(FontStyle==0 || FontStyle==2)Bold.setSelected(false);else Bold.setSelected(true);if(FontStyle==0 || FontStyle==1)Italic.setSelected(false);else Italic.setSelected(true);}public int getStyle(){int bold=0,italic=0;if(Bold.isSelected()) bold=1;if(Italic.isSelected()) italic=1;return bold+italic*2;}public void windowActivated(WindowEvent arg0) {}public void windowClosed(WindowEvent arg0) {}public void windowDeactivated(WindowEvent arg0) {}public void windowDeiconified(WindowEvent arg0) {}public void windowIconified(WindowEvent arg0) {}public void windowOpened(WindowEvent arg0) {} }//创建关于对话框class AboutDialog extends JDialog implements ActionListener{ public JButton OK,Icon;public JLabel Name,Version,Author,Java;public JPanel Panel;AboutDialog(JFrame owner) {super(owner,"关于",true);OK=new JButton("OK");Icon=new JButton(new ImageIcon("icons\\edit.gif"));Name=new JLabel("Notepad");Version=new JLabel("Version 1.0");Java=new JLabel("JRE Version 6.0");Author=new JLabel("Copyright (c) 11-5-2012 By Jianmin Chen");Panel=new JPanel();Color c=new Color(0,95,191);Name.setForeground(c);Version.setForeground(c);Java.setForeground(c);Author.setForeground(c);Panel.setBackground(Color.white);OK.setFocusable(false);this.setBounds(250,200,280, 180);this.setResizable(false);this.setLayout(null);Panel.setLayout(null);OK.addActionListener(this);Icon.setFocusable(false);Icon.setBorderPainted(false);Author.setFont(new Font(null,Font.PLAIN,11));Panel.add(Icon);Panel.add(Name);Panel.add(Version);Panel.add(Author);Panel.add(Java);this.add(Panel);this.add(OK);Panel.setBounds(0, 0, 280, 100);OK.setBounds(180, 114, 72, 26);Name.setBounds(80, 10, 160, 20);Version.setBounds(80, 27, 160, 20);Author.setBounds(15, 70, 250, 20);Java.setBounds(80, 44, 160, 20);Icon.setBounds(16, 14, 48, 48);}public void actionPerformed(ActionEvent e) { this.setVisible(false);}}}//创建记事本public class ChenJianmin {public static void main(String[] args){EventQueue.invokeLater(new Runnable() {public void run() {NotePad notePad=new NotePad();notePad.setTitle("记事本");notePad.setVisible(true);notePad.setBounds(100,100,800,600);notePad.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);}});}}。
用vs编译PythOn源码
观察变量
在断点暂停执行后,可以使用 Visual Studio的“局部变量”窗 口查看当前执行上下文中的变量 值。此外,还可以使用“监视” 窗口添加要观察的表达式或变量 。
单步执行代码和逐行调试
单步执行代码
在断点暂停执行后,可以使用Visual Studio的“调试”菜单或工具栏上的按钮进 行单步执行。可以选择“步入”以进入函数 或方法的内部,或选择“步过”以执行当前 行的代码并移动到下一行。
使用Cython编译器优化Python代码的步骤包括:安装 Cython、编写Cython扩展、编写setup.py文件、执行 `python setup.py build_ext --inplace`命令等。
使用Numba库加速Python代码的运行速度
Numba是一个开源的Python库,它可以将Python代码转换为快速的机器码,从而提高代码的运行效率。
在选项对话框中,选择“Python”选项卡,然后配置 Python解释器和环境变量。
03
编译Python源码
打开VS并创建一个新的Python项目
01
02
03
打开Visual Studio,选择“创建新项 目”。
在“创建新项目”对话框中,选择 “Python”类别,然后选择 “Python应用程序”模板。
在项目模板列表中选择 “Python扩展”,然后点击“ 下一步”。
为项目指定名称和位置,然后 点击“创建”。
选择Python解释器和所需的 Python版本,然后点击“完成 ”以创建项目。
将C代码添加到项目中并配置项目属性
01
02
03
在解决方案资源管理器中,右键单击 项目名称,然后选择“添加”>“现 有项”。
VB.NETVB2010自己动手做记事本源码
VB2010自己动手做记事本源码Imports System.IOPublic Class Form1Dim TempPath As StringPrivate Sub打开OToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles打开OToolStripMenuItem.ClickTryOpenFileDialog1.FileName = ""OpenFileDialog1.Filter = "文本文档|*.txt"OpenFileDialog1.InitialDirectory = "C:\"OpenFileDialog1.ShowDialog()TextBox1.Text = File.ReadAllText(OpenFileDialog1.FileName, System.Text.Encoding.Default)TempPath = OpenFileDialog1.FileNameCatch ex As ExceptionMsgBox(ex.Message)End TryEnd SubPrivate Sub保存SToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles保存SToolStripMenuItem.ClickTryFile.WriteAllText(TempPath, TextBox1.Text, System.Text.Encoding.Default) Catch ex As Exception MsgBox(ex.Message)End TryEnd SubPrivate Sub另存为AToolStripMenuItem_Click(ByVal senderAToolStripMenuItem.ClickTrySaveFileDialog1.ShowDialog()Catch ex As ExceptionMsgBox(ex.Message)End TryEnd SubPrivate Sub新建NToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles新建NToolStripMenuItem.Click'TextBox1.Text = ""TextBox1.Clear()End SubPrivate Sub撤消UToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles撤消UToolStripMenuItem.ClickTextBox1.Undo()End SubPrivate Sub重复RToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles重复RToolStripMenuItem.ClickTextBox1.Undo()End SubPrivate Sub剪切TToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles剪切TToolStripMenuItem.ClickTextBox1.Cut()End SubPrivate Sub复制CToolStripMenuItem_Click(ByVal sender AsCToolStripMenuItem.ClickTextBox1.Copy()End SubPrivate Sub粘贴PToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles粘贴PToolStripMenuItem.ClickTextBox1.Paste()End SubPrivate Sub全选AToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles全选AToolStripMenuItem.ClickTextBox1.SelectAll()End SubPrivate Sub自动换行CT oolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles自定义CToolStripMenuItem.ClickIf TextBox1.WordWrap = True ThenTextBox1.WordWrap = FalseElseTextBox1.WordWrap = TrueEnd IfEnd SubPrivate Sub退出XToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles退出XToolStripMenuItem.ClickMe.Close()End SubPrivate Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load End SubEnd Class。
vb编写的记事本程序vs05
End If
bSave = True
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
OpenFileDialog1.Title = "打开" '对打开文件对话框初始化
End Sub
Private Sub 新建_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles 新建.Click
If SaveFileDialog1.ShowDialog() Then
rtContent.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
'如果文本内容改变或者没有保存,则弹出消息框询问用户是否保存
Select Case flag
Case 6 '如果选择保存,执行保存的操作
If SaveFileDialog1.FileName = "" Then
Case 7 '选择了不保存,则直接执行打开文件
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
rtContent.SaveFile(SaveFileDialog1.FileName, RichTextBoxStreamType.PlainText)
End If '如果没有选择要保存的文件名,则弹出对话框,用户选择文件名后保存文本
Else
Qt:记事本源代码
Qt:记事本源代码界⾯编程之实例学习,系统记事本是个极好的参考,初学Delphi及后之c#,皆以记事本为参考,今以Qt学习,亦是如此。
期间搭建开发环境,复习c++知识,寻找模块对应功能,不⼀⽽⾜;现刻录其模块代码,以做助记,功能接近系统记事本之95%。
学习了Qt事件驱动之信号槽机投、窗体间数据传递⽅法、⽂件编码、本地化等功能,然⽽初接触,仍不能得⼼应⼿。
IDE: VS2015+Qt5.8.0界⾯如下:直贴源代码吧!完成源码包,附于⽂后。
1、⼊⼝程序(main.cpp):#pragma execution_character_set("utf-8")#include <QtWidgets/QApplication>#include "qtranslator.h"#include "notepad.h"int main(int argc, char *argv[]){QApplication a(argc, argv);//对话框类应⽤中⽂QTranslator user;bool ok = user.load("qt_zh_CN.qm", ".");a.installTranslator(&user);NotePad np;if (argc >= 2){QString s = QString::fromLocal8Bit(argv[1]);np.loadFromFile(s);}np.show();return a.exec();}2、主模块(notepad.cpp):#include <qfileinfo.h>#include <qfile.h>#include <qmimedata.h>#include <qtextstream.h>#include <qprinter.h>#include <qprintdialog.h>#include <qpagesetupdialog.h>#include <qfiledialog.h>#include <qfontdialog.h>#include <qmessagebox.h>#include <qtextobject.h>#include <qdatetime.h>#include <qsettings.h>#include "notepad.h"NotePad::NotePad(QWidget *parent): QMainWindow(parent){ui.setupUi(this);//searchDialog = new SearchDialog(Q_NULLPTR, ui.textEdit);lblStatus = new QLabel();lblStatus->setAlignment(Qt::AlignRight);statusBar()->addPermanentWidget(lblStatus);setActionState();initTextEdifUI();loadSettings();}void NotePad::loadSettings(){//⼤⼩&位置QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Notepad", QSettings::NativeFormat); int x = settings.value("iWindowPosX", 0).toInt();int y = settings.value("iWindowPosY", 0).toInt();int w = settings.value("iWindowPosDX", 800).toInt();int h = settings.value("iWindowPosDY", 600).toInt();this->setGeometry(x, y, w, h);ui.actWordWrap->setChecked(settings.value("fWrap", true).toBool());ui.actStatus->setChecked(settings.value("StatusBar", true).toBool());ui.statusBar->setVisible(ui.actStatus->isChecked());}void NotePad::saveSettings(){//⼤⼩&位置QSettings settings("HKEY_CURRENT_USER\\Software\\Microsoft\\Notepad", QSettings::NativeFormat); settings.setValue("iWindowPosX", this->x());settings.setValue("iWindowPosY", this->y());settings.setValue("iWindowPosDX", this->width());settings.setValue("iWindowPosDY", this->height());settings.setValue("fWrap", ui.actWordWrap->isChecked());settings.setValue("StatusBar", ui.actStatus->isChecked());}void NotePad::setFileName(QString fileName){this->fileName = fileName;ui.textEdit->document()->setModified(false);QString shownName;if (fileName.isEmpty())shownName = tr("未命名");elseshownName = QFileInfo(fileName).fileName();setWindowTitle(tr("%1[*] - %2").arg(shownName, tr("记事本")));setWindowModified(false);lastDir = QFileInfo(fileName).absoluteDir().absolutePath();}void NotePad::loadFromFile(QString fileName){QFileInfo fileInfo(fileName);if (!fileInfo.isFile())return;QFile file(fileName);if (!file.open(QIODevice::ReadOnly)){QMessageBox::warning(this, tr("提⽰"), tr("不能打开此⽂件!"), tr("确定"));return;}setFileName(fileName);QTextStream in(&file);}void NotePad::dragEnterEvent(QDragEnterEvent *event){if (event->mimeData()->hasFormat("text/uri-list"))event->acceptProposedAction();}void NotePad::dropEvent(QDropEvent *event){QList<QUrl> urls = event->mimeData()->urls();if (urls.isEmpty())return;QString fileName = urls.first().toLocalFile();if (!fileName.isEmpty())loadFromFile(fileName);}void NotePad::closeEvent(QCloseEvent * event){if (confirmSave()){saveSettings();event->accept();}elseevent->ignore();}bool NotePad::confirmSave(){if (!ui.textEdit->document()->isModified())return true;QMessageBox::StandardButtons sb = QMessageBox::question(this, tr("提⽰"), tr("是否将更改保存到 %1?").arg(this->windowTitle().replace(tr(" - 记事本"), "")), tr("保存(&S)"), tr("不保存(&N)"), tr("取消"));switch (sb){case0:return saveFile();case1:return true;case2:return false;default:return true;}}bool NotePad::saveFile(){if (this->fileName.isEmpty())return saveFileAs();return saveFile(this->fileName);}bool NotePad::saveFile(QString fileName){if (!ui.textEdit->document()->isModified())return false;QFile file(fileName);if (!file.open(QFile::WriteOnly | QFile::Text)){QMessageBox::critical(this, tr("提⽰"), tr("不能写⼊⽂件!"), tr("确定"));return false;}QTextStream out(&file);out << ui.textEdit->toPlainText();setFileName(fileName);return true;}bool NotePad::saveFileAs(){QString fileName = QFileDialog::getSaveFileName(this, tr("另存为"),lastDir + tr("./未命名.txt"), tr("⽂本⽂档(*.txt);;所有⽂件(*.*)"));if (fileName.isEmpty())return false;return saveFile(fileName);}void NotePad::setActionState()ui.actUndo->setEnabled(false);ui.actCopy->setEnabled(false);ui.actCut->setEnabled(false);ui.actDelete->setEnabled(false);ui.actFind->setEnabled(false);ui.actFindNext->setEnabled(false);ui.actGoto->setEnabled(false);}void NotePad::initTextEdifUI(){QPalette palette = ui.textEdit->palette();palette.setColor(QPalette::Highlight, Qt::darkGreen);palette.setColor(QPalette::HighlightedText, Qt::white);ui.textEdit->setPalette(palette);ui.textEdit->setAcceptDrops(false);setAcceptDrops(true);}//槽函数void NotePad::slotNew(){if (!confirmSave())return;ui.textEdit->clear();setFileName("");}void NotePad::slotOpen(){if (!confirmSave())return;QString fileName = QFileDialog::getOpenFileName(this, tr("另存为"), lastDir, tr("⽂本⽂档(*.txt);;所有⽂件(*.*)"));if (!fileName.isEmpty())loadFromFile(fileName);}void NotePad::slotSave(){saveFile();}void NotePad::slotSaveAs(){saveFileAs();}void NotePad::slotPageSetup(){QPrinter printer;QPageSetupDialog pageSetUpdlg(&printer, this);if (pageSetUpdlg.exec() == QDialog::Accepted)printer.setOrientation(QPrinter::Landscape);elseprinter.setOrientation(QPrinter::Portrait);}void NotePad::slotPrint(){QPrinter printer;QString printerName = printer.printerName();if (printerName.size() == 0)return;QPrintDialog dlg(&printer, this);if (ui.textEdit->textCursor().hasSelection())dlg.addEnabledOption(QAbstractPrintDialog::PrintSelection);// 如果在对话框中按下了打印按钮,则执⾏打印操作if (dlg.exec() == QDialog::Accepted)ui.textEdit->print(&printer);}void NotePad::slotExit(){this->close();}void NotePad::slotUndo(){ui.textEdit->undo();}void NotePad::slotCut()ui.textEdit->cut();}void NotePad::slotCopy(){ui.textEdit->copy();}void NotePad::slotPaste(){ui.textEdit->paste();}void NotePad::slotDelete(){ui.textEdit->textCursor().removeSelectedText();}void NotePad::slotFind(){if (replaceDialog != Q_NULLPTR && replaceDialog->isVisible()){replaceDialog->activateWindow();return;}if (searchDialog == Q_NULLPTR)searchDialog = new SearchDialog(this, ui.textEdit);searchDialog->show();searchDialog->activateWindow();}void NotePad::slotFindNext(){if (searchDialog == Q_NULLPTR)searchDialog = new SearchDialog(this, ui.textEdit);searchDialog->search();}void NotePad::slotReplace(){if (searchDialog != Q_NULLPTR && searchDialog->isVisible()){searchDialog->activateWindow();return;}if (replaceDialog == Q_NULLPTR)replaceDialog = new ReplaceDialog(this, ui.textEdit);replaceDialog->show();replaceDialog->activateWindow();}void NotePad::slotGoto(){//跳转...传this以此做为其窗主,Modal状态标题栏闪烁GotoDialog gotoDialog(this);gotoDialog.setLineNumber(ui.textEdit->textCursor().blockNumber() + 1, ui.textEdit->document()->lineCount()); if (gotoDialog.exec() == QDialog::Accepted){int line = gotoDialog.gotoLine;QTextCursor cursor = ui.textEdit->textCursor();int position = ui.textEdit->document()->findBlockByNumber(line - 1).position();cursor.setPosition(position, QTextCursor::MoveAnchor);ui.textEdit->setTextCursor(cursor);}}void NotePad::slotSelectAll(){ui.textEdit->selectAll();}void NotePad::slotDatetime(){QString dateTime = QDateTime::currentDateTime().toString(Qt::SystemLocaleDate);ui.textEdit->textCursor().insertText(dateTime);}void NotePad::slotWordWrap(){if (ui.actWordWrap->isChecked())ui.textEdit->setWordWrapMode(QTextOption::WordWrap);elseui.textEdit->setWordWrapMode(QTextOption::NoWrap);ui.actGoto->setEnabled(!ui.actWordWrap->isChecked());ui.actStatus->setEnabled(ui.actWordWrap->isChecked());{if (ui.actStatus->isChecked()){ui.actStatus->setChecked(false);ui.statusBar->setVisible(ui.actStatus->isChecked());}}else if (this->statusChecked)ui.actStatus->trigger();}void NotePad::slotFont(){bool ok;QFont font = QFontDialog::getFont(&ok, ui.textEdit->font());if (ok)ui.textEdit->setFont(font);}void NotePad::slotStatus(){this->statusChecked = ui.actStatus->isChecked();ui.statusBar->setVisible(ui.actStatus->isChecked());}void NotePad::slotHelp(){QMessageBox::warning(this, tr("提⽰"), tr("黔驴技穷,搞不定[IHxHelpPane->(\"mshelp://windows/?id=e725b43f-94e4-4410-98e7-cc87ab2739aa\")]"), tr("确定")); //HxHelpPane *helpPane = new HxHelpPane();//CoInitialize(NULL);//IHxHelpPane *helpPane = NULL;//HRESULT hr = ::CoCreateInstance(CLSID_HxHelpPane, NULL, CLSCTX_ALL, IID_IHxHelpPane, reinterpret_cast<void**>(&helpPane));//if (SUCCEEDED(hr))// helpPane->DisplayTask(BSTR("mshelp://windows/?id=e725b43f-94e4-4410-98e7-cc87ab2739aa"));}void NotePad::slotAbout(){QString appPath = QApplication::applicationFilePath();HICON icon = ExtractIcon(NULL, appPath.toStdWString().c_str(), 0);ShellAbout((HWND)this->winId(), tr("Qt记事本").toStdWString().c_str(), tr("作者:刘景威").toStdWString().c_str(), icon);}void NotePad::slotCopyAvailable(bool enabled){ui.actCopy->setEnabled(enabled);}void NotePad::slotCursorPositionChanged(){QTextCursor tc = ui.textEdit->textCursor();QString info = tr("第%1⾏,第%2列 ").arg(tc.blockNumber() + 1).arg(tc.columnNumber());lblStatus->setText(info);}void NotePad::slotRedoAvailable(bool enabled){}void NotePad::slotSelectionChanged(){QString selecdedText = ui.textEdit->textCursor().selectedText();//ui.actUndoui.actCopy->setEnabled(!selecdedText.isEmpty());ui.actCut->setEnabled(!selecdedText.isEmpty());ui.actDelete->setEnabled(!selecdedText.isEmpty());}void NotePad::slotTextChanged(){slotSelectionChanged();QString text = ui.textEdit->toPlainText();ui.actFind->setEnabled(text != "");ui.actFindNext->setEnabled(text != "");ui.actGoto->setEnabled(text != "" && !ui.actWordWrap->isChecked());}void NotePad::slotUndoAvailable(bool enabled){ui.actUndo->setEnabled(enabled);}3、跳转模块(goto.cpp)GotoDialog::GotoDialog(QWidget *parent) :QDialog(parent){ui.setupUi(this);setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint | Qt::MSWindowsFixedSizeDialogHint); bel->setBuddy(ui.lineEdit);QRegExp regx("[0-9]+$");QValidator *validator = new QRegExpValidator(regx, this);ui.lineEdit->setValidator(validator);}GotoDialog::~GotoDialog(){}void GotoDialog::setLineNumber(int currLine, int maxLineCount){ui.lineEdit->setText(QString::number(currLine));ui.lineEdit->selectAll();this->maxLineCount = maxLineCount;}void GotoDialog::accept(){QString value = ui.lineEdit->text().trimmed();if (value.isEmpty()){this->showMessage(tr("请输⼊要跳到的⾏数。
VS2019创建代码模板
VS2019创建代码模板⽬录Code SnippetCode Snippet,与其称其为代码⽚段(Code Block),将它翻译成代码模板(Code Template)可能更合适⼀些。
任何⼀段代码都可以叫做代码⽚段,我们这⾥要讲的不是这种随性的东西,⽽是⼀种快速⽣成代码的快捷⽅式,通过它可以有效地提⾼我们的编程效率。
举个例⼦,假如你在C#代码编辑器中输⼊propfull,再连续摁俩下Tab键进⾏代码补全,将会⾃动为你⽣成以下代码段:private int myVar;public int MyProperty{get { return myVar; }set { myVar = value; }}编辑器⾥是这样⼦的:此时光标处于第⼀个int位置,键⼊任何其他类型都会置换int,并且你可以通过Tab键位跳到下⼀个可修改的地⽅(背景⾊为黄⾊),这个模板⾥提供了3个可修改的位置,int,myVar以及MyProperty。
当你修改myVar的时候,你可以通过"Alt+Enter"或者"Ctrl+."将其他引⽤了myVar的地⽅进⾏快速替换。
你仅仅通过输⼊⼏个字符,就完成了⼀⼤段代码的创建,为你省下不少时间,试想⼀下你创建过的封装属性何其的多,仅这⼀项就可以⼤⼤的提⾼你的⼯作效率。
你也通过其他的第三⽅扩展或者通过"快速操作->封装字段"也可以实现类似的效果。
Microsoft为你内置了不少语⾔的不少代码模板,如下图所⽰是C#内置的Code Snippet:我们可以按位置在本地找到相应的代码⽚段,都是.snippet⽂件,我们⽤记事本打开propfull.snippet⽂件,⾥⾯的内容如下所⽰:<?xml version="1.0" encoding="utf-8"?><CodeSnippets xmlns="/VisualStudio/2005/CodeSnippet"><CodeSnippet Format="1.0.0"><Header><Title>propfull</Title><Shortcut>propfull</Shortcut><Description>属性和⽀持字段的代码⽚段</Description><Author>Microsoft Corporation</Author><SnippetTypes><SnippetType>Expansion</SnippetType></SnippetTypes></Header><Snippet><Declarations><Literal><ID>type</ID><ToolTip>属性类型</ToolTip><Default>int</Default></Literal><Literal><ID>property</ID><ToolTip>属性名</ToolTip><Default>MyProperty</Default></Literal><Literal><ID>field</ID><ToolTip>⽀持此属性的变量</ToolTip><Default>myVar</Default></Literal></Declarations><Code Language="csharp"><![CDATA[private $type$ $field$;public $type$ $property${get { return $field$;}set { $field$ = value;}}$end$]]></Code></Snippet></CodeSnippet></CodeSnippets>虽然你也可以通过直接修改这个xml⽂档来修改代码模板,但我们更推荐使⽤Visual Studio的⼀个可视化扩展,叫Snippet Designer。
怎样使用VS写C语言(C++)代码[小白向]
怎样使⽤VS写C语⾔(C++)代码[⼩⽩向]本节,我们学习如何在新版 VS 2017 中编写程序输出“C语⾔中⽂⽹”,程序代码如下:1. #include <stdio.h>2. int main()3. {4. puts("C语⾔中⽂⽹");5. return 0;6. }创建项⽬(Project)在 VS 2017 下开发程序⾸先要创建项⽬,不同类型的程序对应不同类型的项⽬,初学者应该从控制台程序学起。
打开 VS 2017,在菜单栏中依次选择 “⽂件 --> 新建 --> 项⽬”:或者直接按下 Ctrl+Shift+N 组合键,都会弹出下⾯的对话框:选择 “空项⽬”,填写好项⽬名称,选择好存储路径,同时对于初学者来说,可取消勾选 “为解决⽅案创建⽬录”,点击 “确定” 按钮即可。
注意:这⾥⼀定要选择 “空项⽬” ⽽不是 “Windows控制台应⽤程序”,因为后者会导致项⽬中⾃带有很多莫名其妙的⽂件,不利于初学者对项⽬的理解。
另外,项⽬名称和存储路径中最好不要包含中⽂。
点击 “确定” 按钮后,会直接进⼊项⽬可操作界⾯,我们将在这个界⾯完成所有的编程⼯作。
有兴趣的同学可以打开项⽬的存储路径(本⽂的项⽬存储路径为 D:\Demo\),会发现多了⼀个 Demo ⽂件夹,这就是存储整个项⽬的⽂件夹。
添加源⽂件在 “源⽂件” 处右击⿏标,在弹出菜单中选择 “添加 --> 新建项” ,如下图所⽰:或者直接按下 Ctrl + shift + A 组合键,都会弹出添加源⽂件的对话框,如下图所⽰:在此分类中,我们选择 “C++⽂件(.cpp)”,编写 C 语⾔程序时,注意源⽂件后缀名为 .c ,点击 “添加” 按钮,就添加上了⼀个新的源⽂件。
注意:C++ 是在 C 语⾔的基础上进⾏的扩展,所有在本质上,C++ 已经包含了 C 语⾔的所有内容,所以⼤部分 IDE 会默认创建后缀名为 .cpp 的C++ 源⽂件。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 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 = "本程序由本人初次制作,内容可能还有些许漏洞,如果在您使用过程中发现问题,敬请联系本人。