谁能举一个简短的示例,说明如何使用c ++开发Windows窗体应用程序以及如何在cpp文件中编写代码。
问题是,
我只需要在myform.h中编写整个运行时代码,就不能在cpp或ac文件中编写任何代码吗?
就像在C ++标准程序中一样,您可以在cpp文件中编写代码,例如:
对于button事件,将其原型放在头文件中:
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e);
然后,在C ++源文件中,您可以执行以下操作:
#include "stdafx.h"
#include "Form1.h"
using namespace System;
using namespace System::Windows::Forms;
using namespace <your_project_namespace>;
Void Form1::button1_Click(Object^ sender, EventArgs^ e)
{
double result = 0.0;
double input;
if (Double::TryParse(this->textBox1->Text, input))
{
result = input * 2.5;
this->label1->Text = "Result= " + result + ".";
}
}
不要忘了包含您的Form头文件,并使用良好的名称空间。查看结果:
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句