就一个自己做得简单的记事本,几年前的了
form2.h //登陆界面
private: System::Void checkBox1_CheckedChanged(System::Object^ sender, System::EventArgs^ e) {
textBox2->PasswordChar=checkBox1->Checked ? 0 : '*’;
} //显示密码checkBox按钮
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
if(textBox1->Text==String::Empty && textBox2->Text==String::Empty){
MessageBox::Show(L"输入用户名及密码错误,请核对!");
return; //判断用户是否输入用户名,否者提示
}
else if(textBox2->Text==String::Empty){
MessageBox::Show(L"输入密码错误,请核对!");
return; //若未输入密码,者提示
}
else if(textBox1->Text==String::Empty){
MessageBox::Show(L"输入用户名错误,请核对!");
return; //未输入用户名,弹窗提示
}
else
{
MessageBox::Show(L"登录成功!");//用户名及密码正确,弹窗提示
this->Close(); //关闭登录界面,打开用户界面
}
}
private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
Application::Exit(); //若按下退出键,者关闭程序
}
form1.h //
用户界面程序
rm2^ form = gcnew form2();
if (form->ShowDialog() != System::Windows::Forms::DialogResult::OK)
return; //调用登录界面
private: System::Void newMenu_Click(System::Object^ sender, System::EventArgs^ e) {
this->textBox1->Text=nullptr;
this->Text=L"无标题—记事本";
} //新建功能的具体实现
private: System::Void openMenu_Click(System::Object^ sender, System::EventArgs^ e) {
OpenFileDialog^ dlg = gcnew OpenFileDialog();
dlg->FileName = L"*.txt"; // 缺省文件名dlg->Filter = L"文本文档(*.txt)|*.txt|所有文件(*.*)|*.*"; // 过滤字符串if (dlg->ShowDialog() != System::Windows::Forms::DialogResult::OK)
return; // 未选择文件, 退出
try {
FileInfo^ fileInfo = gcnew FileInfo(dlg->FileName);
FileStream^ stream = fileInfo->Open(FileMode::OpenOrCreate, FileAccess::Read);
StreamReader^ reader = gcnew StreamReader(stream, Encoding::UTF8);
String^ readText;
this->textBox1->Text = nullptr;
while ((readText = reader->ReadLine()) != nullptr) // 读取一行文本
this->textBox1->Text += readText + "\r\n"; // 添加到TextBox中
reader->Close(); // 关闭StreamReader
stream->Close(); // 关闭FileStream
this->Text = fileInfo->Name + L" - 记事本"; // 设置窗体的标题
}
catch (IOException^ e) { // 打开失败,或其他异常
MessageBox::Show(e->ToString());
}
} //打开按钮的具体实现
private: System::Void saveMenu_Click(System::Object^ sender, System::EventArgs^ e) {
SaveFileDialog^dlg=gcnew SaveFileDialog();
dlg->FileName=DateTime::Now.ToString(L"yyyy年MM月dd日HH点mm分ss秒")+L".text"; //默认时间保存
dlg->Filter=L"文本文档(*.text)|*.text|所有文件(*.*)|*.*";
if(dlg->ShowDialog()!=System::Windows::Forms::DialogResult::OK)
return;
try{
FileInfo^fileInfo=gcnew FileInfo(dlg->FileName);
FileStream^stream=
fileInfo->Open(FileMode::OpenOrCreate,FileAccess::Write);
StreamWriter^writer=
gcnew StreamWriter(stream,Encoding::UTF8);
for each (String^lineText in this->textBox1->Lines)
writer->WriteLine(lineText);
writer->Close();
stream->Close();
this->textBox1->Modified=false;
}
catch(IOException^ e){
MessageBox::Show(e->ToString());
}
listBox1->Items->Add(DateTime::Now.ToString(L"yyyy年MM月dd日HH点mm分ss秒")); //在组合列表里面显示保存记录
} //保存按钮的具体实现
private: System::Void exitMenu_Click(System::Object^ sender, System::EventArgs^ e) {
if(this->textBox1->Modified){
if (MessageBox::Show(L"是否保存文件?",L"提示",MessageBoxButtons::OKCancel)==
System::Windows::Forms::DialogResult::OK)
saveMenu_Click(sender,e);
}
Application::Exit();
} //退出按钮的具体实现
private: System::Void cutMenu_Click(System::Object^ sender, System::EventArgs^ e) {
this->textBox1->Cut();
}//剪切按钮具体实现
private: System::Void copyMenu_Click(System::Object^ sender, System::EventArgs^ e) {
this->textBox1->Copy();
}//复制按钮的具体实现
private: System::Void pasteMenu_Click(System::Object^ sender, System::EventArgs^ e) {
this->textBox1->Paste();
}//粘贴按钮的具体实现
private: System::Void fontMenu_Click(System::Object^ sender, System::EventArgs^ e) {
FontDialog^ dlg=gcnew FontDialog();
dlg->Font=this->textBox1->Font;
if(dlg->ShowDialog()==System::Windows::Forms::DialogResult::OK)
this->textBox1->Font=dlg->Font;
}//调用字体功能框,调节字形字体大小的具体实现
private: System::Void timer1Tick(System::Object^ sender, System::EventArgs^ e) {
static int i=0;i=(i<6 ? i+1 : 0);
pictureBox1->Image=(gcnew System::Drawing ::Icon(L"face"+i+L".ico",64,64))->ToBitmap();
label12->Text=DateTime::Now.ToString(L"yyyy年MM月dd日\r\n HH点mm分ss秒");
progressBar1->Value=DateTime::Now.Second;
}//图片切换、系统时间、60秒进度等功能的实现
地址:http://pan.baidu.com/share/link?shareid=3760567427&uk=1259703658