基于窗体的程序设计方法的研究.docx
- 文档编号:13833567
- 上传时间:2023-06-17
- 格式:DOCX
- 页数:14
- 大小:89.23KB
基于窗体的程序设计方法的研究.docx
《基于窗体的程序设计方法的研究.docx》由会员分享,可在线阅读,更多相关《基于窗体的程序设计方法的研究.docx(14页珍藏版)》请在冰点文库上搜索。
基于窗体的程序设计方法的研究
实验三基于窗体的程序设计方法的研究
姓名:
魏博航
学号:
13521301
专业:
通信工程
指导教师:
李家军
实验日期:
2015年5月17日
一、问题陈述
设计如下界面所示的窗体程序,点击“计算”按钮后程序自动计算出输入的两个正数是否能代表一个合理的区间,如果能则计算出该区间之内的所有质数(素数),并显示在右边的列表框中,同时在“计算结果”右侧的文本框中显示出“[xxx,yyy]之内有zzz个素数”。
如果不能,则显示“输入数据无效!
”。
点击“清空”则将各个文本框中的内容清除。
点击“退出”按钮则终止程序执行。
二、算法分析及关键代码设计,主要程序结构,数据结构说明
主要程序:
//判断是否为素数的自定义函数
BooleanisPrime(Int64n){
Int64m=Math:
:
Sqrt(n);
Int64i;
for(i=2;i<=m;i++)
if(n%i==0)break;
if(i>=m+1){
count++;
returntrue;
}else
returnfalse;
}
//按钮点击事件参数
this->CalculateButton->Click+=gcnewSystem:
:
EventHandler(this,@amp;Form1:
:
CalculateButton_Click);
this->ClearButton->Click+=gcnewSystem:
:
EventHandler(this,@amp;Form1:
:
ClearButton_Click);
this->ExitButton->Click+=gcnewSystem:
:
EventHandler(this,@amp;Form1:
:
ExitButton_Click);
//程序参数重置
this->FromText->Clear();
this->ToText->Clear();
this->ListBox->Text="";
this->ResultCount->Text="";
count=0;
//从文本框中获取并转换为整型数参数
a=Int64:
:
Parse(FromText->Text);
b=Int64:
:
Parse(ToText->Text);
//输出结果文本框显示样式
this->ListBox->Text+=n.ToString()+"";
this->ListBox->Refresh();
//退出按钮参数
this->Close();
//为了保证程序界面的美观,在窗体中设置了以下参数
this->MaximizeBox=false;
this->MaximumSize=System:
:
Drawing:
:
Size(500,400);
this->MinimumSize=System:
:
Drawing:
:
Size(500,400);
三、实验结果截图及结果讨论
1.实验结果截图
启动调试初始界面:
输入两正整数时的程序输出运行结果:
输入值异常时的程序报错:
2.结果讨论
实验结果完全符合要求,与预期要求一样,输入值正常和异常时,运行结果良好。
四、实验心得体会
我在参考了课外书资料后,尽可能编写,完成了这次实验内容要求,编写窗体程序可以感受到更人性化的界面体验,感觉窗体程序编写成功后有了极大的成就感,感觉这才是真正的程序。
五、原程序附录及注释
//project3.cpp
//project3.cpp:
mainprojectfile.
#include"stdafx.h"
#include"Form1.h"
usingnamespaceproject3;
[STAThreadAttribute]
intmain(array : String^>^args) { //EnablingWindowsXPvisualeffectsbeforeanycontrolsarecreated Application: : EnableVisualStyles(); Application: : SetCompatibleTextRenderingDefault(false); //Createthemainwindowandrunit Application: : Run(gcnewForm1()); return0; } //Form1.h #pragmaonce namespaceproject3{ usingnamespaceSystem; usingnamespaceSystem: : ComponentModel; usingnamespaceSystem: : Collections; usingnamespaceSystem: : Windows: : Forms; usingnamespaceSystem: : Data; usingnamespaceSystem: : Drawing; /// ///SummaryforForm1 /// publicrefclassForm1: publicSystem: : Windows: : Forms: : Form { public: Form1(void) { InitializeComponent(); // //TODO: Addtheconstructorcodehere // } BooleanisPrime(Int64n){//判断是否为素数的自定义函数 Int64m=Math: : Sqrt(n); Int64i; for(i=2;i<=m;i++) if(n%i==0)break; if(i>=m+1){ count++; returntrue; }else returnfalse; } protected: /// ///Cleanupanyresourcesbeingused. /// ~Form1() { if(components) { deletecomponents; } } private: System: : Windows: : Forms: : Button^CalculateButton; private: System: : Windows: : Forms: : Label^ConstFrom; private: System: : Windows: : Forms: : Label^ConstTo; private: System: : Windows: : Forms: : Button^ClearButton; private: System: : Windows: : Forms: : Button^ExitButton; private: System: : Windows: : Forms: : TextBox^FromText; private: System: : Windows: : Forms: : TextBox^ToText; private: System: : Windows: : Forms: : Label^ConstResult; private: System: : Windows: : Forms: : Label^ResultCount; private: System: : Windows: : Forms: : Label^ConstHelp; private: System: : Windows: : Forms: : TextBox^ListBox; private: Int64a,b,count;//变量的声明 /// ///Requireddesignervariable. /// System: : ComponentModel: : Container^components; #pragmaregionWindowsFormDesignergeneratedcode /// ///RequiredmethodforDesignersupport-donotmodify ///thecontentsofthismethodwiththecodeeditor. /// voidInitializeComponent(void) { this->CalculateButton=(gcnewSystem: : Windows: : Forms: : Button()); this->ConstFrom=(gcnewSystem: : Windows: : Forms: : Label()); this->ConstTo=(gcnewSystem: : Windows: : Forms: : Label()); this->ClearButton=(gcnewSystem: : Windows: : Forms: : Button()); this->ExitButton=(gcnewSystem: : Windows: : Forms: : Button()); this->FromText=(gcnewSystem: : Windows: : Forms: : TextBox()); this->ToText=(gcnewSystem: : Windows: : Forms: : TextBox()); this->ConstResult=(gcnewSystem: : Windows: : Forms: : Label()); this->ResultCount=(gcnewSystem: : Windows: : Forms: : Label()); this->ConstHelp=(gcnewSystem: : Windows: : Forms: : Label()); this->ListBox=(gcnewSystem: : Windows: : Forms: : TextBox()); this->SuspendLayout(); // //CalculateButton // this->CalculateButton->Location=System: : Drawing: : Point(364,47); this->CalculateButton->Name=L"CalculateButton"; this->CalculateButton->Size=System: : Drawing: : Size(78,25); this->CalculateButton->TabIndex=2; this->CalculateButton->Text=L"Calculate"; this->CalculateButton->UseVisualStyleBackColor=true; this->CalculateButton->Click+=gcnewSystem: : EventHandler(this,@amp;Form1: : CalculateButton_Click); // //ConstFrom // this->ConstFrom->AutoSize=true; this->ConstFrom->Location=System: : Drawing: : Point(47,50); this->ConstFrom->Name=L"ConstFrom"; this->ConstFrom->Size=System: : Drawing: : Size(35,12); this->ConstFrom->TabIndex=1; this->ConstFrom->Text=L"From: "; // //ConstTo // this->ConstTo->AutoSize=true; this->ConstTo->Location=System: : Drawing: : Point(47,118); this->ConstTo->Name=L"ConstTo"; this->ConstTo->Size=System: : Drawing: : Size(23,12); this->ConstTo->TabIndex=2; this->ConstTo->Text=L"To: "; // //ClearButton // this->ClearButton->Location=System: : Drawing: : Point(364,113); this->ClearButton->Name=L"ClearButton"; this->ClearButton->Size=System: : Drawing: : Size(75,23); this->ClearButton->TabIndex=3; this->ClearButton->Text=L"Clear"; this->ClearButton->UseVisualStyleBackColor=true; this->ClearButton->Click+=gcnewSystem: : EventHandler(this,@amp;Form1: : ClearButton_Click); // //ExitButton // this->ExitButton->Location=System: : Drawing: : Point(364,179); this->ExitButton->Name=L"ExitButton"; this->ExitButton->Size=System: : Drawing: : Size(75,23); this->ExitButton->TabIndex=4; this->ExitButton->Text=L"Exit"; this->ExitButton->UseVisualStyleBackColor=true; this->ExitButton->Click+=gcnewSystem: : EventHandler(this,@amp;Form1: : ExitButton_Click); // //FromText // this->FromText->Location=System: : Drawing: : Point(116,47); this->FromText->Name=L"FromText"; this->FromText->Size=System: : Drawing: : Size(192,21); this->FromText->TabIndex=0; // //ToText // this->ToText->Location=System: : Drawing: : Point(116,115); this->ToText->Name=L"ToText"; this->ToText->Size=System: : Drawing: : Size(192,21); this->ToText->TabIndex=1; // //ConstResult // this->ConstResult->AutoSize=true; this->ConstResult->Location=System: : Drawing: : Point(47,184); this->ConstResult->Name=L"ConstResult"; this->ConstResult->Size=System: : Drawing: : Size(47,12); this->ConstResult->TabIndex=7; this->ConstResult->Text=L"Result: "; // //ResultCount // this->ResultCount->AutoSize=true; this->ResultCount->Location=System: : Drawing: : Point(114,184); this->ResultCount->Name=L"ResultCount"; this->ResultCount->Size=System: : Drawing: : Size(35,12); this->ResultCount->TabIndex=8; this->ResultCount->Text=L"-----"; // //ConstHelp // this->ConstHelp->AutoSize=true; this->ConstHelp->Location=System: : Drawing: : Point(207,184); this->ConstHelp->Name=L"ConstHelp"; this->ConstHelp->Size=System: : Drawing: : Size(101,12); this->ConstHelp->TabIndex=13; this->ConstHelp->Text=L"primenumber(s)."; // //ListBox // this->ListBox->Location=System: : Drawing: : Point(49,226); this->ListBox->MaximumSize=System: : Drawing: : Size(390,100); this->ListBox->MinimumSize=System: : Drawing: : Size(390,100); this->ListBox->Name=L"ListBox"; this->ListBox->Size=System: : Drawing: : Size(390,100); this->ListBox->TabIndex=15; // //Form1 // this->AutoScaleDimensions=System: : Drawing: : SizeF(6,12); this->AutoScaleMode=System: : Windows: : Forms: : AutoScaleMode: : Font; this->ClientSize=System: : Drawing: : Size(484,362); this->Controls->Add(this->ListBox); this->Controls->Add(this->ConstHelp); this->Controls->Add(this->ResultCount); this->Controls->Add(this->ConstResult); this->Controls->Add(this->ToText); this->Controls->Add(this->FromText); this->Controls->Add(this->ExitButton); this->Controls->Add(this->ClearButton); this->Controls->Add(this->ConstTo); this->Controls->Add(this->ConstFrom); this->Controls->Add(this->CalculateButton); this->MaximizeBox=false; this->MaximumSize=System: : Drawing: : Size(500,400); this->MinimumSize=System: : Drawing: : Size(500,400); this->Name=L"Form1"; this->Text=L"PrimeCount"; this->ResumeLayout(false); this->PerformLayout(); } #pragmaendregion private: System: : VoidClearButton_Click(System: : Object^sender,System: : EventArgs^e){ this->FromText->Clear(); this->ToText->Clear(); this->ListBox->Text=""; this->ResultCount->Text=""; count=0; } private: System: : VoidCalculateButton_Click(System: : Object^sender,System: : EventArgs^e){ this->ListBox->Text=""; this->ResultCount->Text="";
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 窗体 程序设计 方法 研究