C++ cli 如何从C++中的NoigIpUpDip中获取值?
我一直在为我的一个小项目试用windows窗体,该程序计算不同数量食物的含量 我认为数字统计是获取食物量信息的好方法 我尝试了以下Microsofts教程,介绍了如何从numericupdown中获取计算值,结果如下:C++ cli 如何从C++中的NoigIpUpDip中获取值?,c++-cli,C++ Cli,我一直在为我的一个小项目试用windows窗体,该程序计算不同数量食物的含量 我认为数字统计是获取食物量信息的好方法 我尝试了以下Microsofts教程,介绍了如何从numericupdown中获取计算值,结果如下: Double testVariable = numericSportfit.Value * 14.4; private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e)
Double testVariable = numericSportfit.Value * 14.4;
private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
}
//Button Räkna
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
MessageBox::Show(testVariable.ToString(), "Resultat");
}
但是,我不断收到错误消息E0153表达式必须具有类类型,C2228在“.Value”的左边必须具有class/struct/union
我正在跑步。
我已经尝试搜索整个Web,关于如何获得C++的值,但我能找到的只有C.。
最初我只是想在C中编程,因为这是我最熟悉的,但是VS似乎只有C++和C. <
下面是整个代码块:
namespace Foderkalkylator {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
/// <summary>
/// Summary for MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
/// <summary>
/// Clean up any resources being used.
/// </summary>
~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::NumericUpDown^ numericSportfit;
protected:
private:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->button1 = (gcnew System::Windows::Forms::Button());
this->numericSportfit = (gcnew System::Windows::Forms::NumericUpDown());
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericSportfit))->BeginInit();
this->SuspendLayout();
//
// button1
//
this->button1->BackColor = System::Drawing::SystemColors::ActiveBorder;
this->button1->Location = System::Drawing::Point(656, 387);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(116, 62);
this->button1->TabIndex = 0;
this->button1->Text = L"Räkna";
this->button1->UseVisualStyleBackColor = false;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// numericSportfit
//
this->numericSportfit->DecimalPlaces = 2;
this->numericSportfit->Location = System::Drawing::Point(94, 55);
this->numericSportfit->Name = L"numericSportfit";
this->numericSportfit->Size = System::Drawing::Size(120, 20);
this->numericSportfit->TabIndex = 1;
this->numericSportfit->ValueChanged += gcnew System::EventHandler(this, &MyForm::numericSportfit_ValueChanged);
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(784, 461);
this->Controls->Add(this->numericSportfit);
this->Controls->Add(this->button1);
this->Name = L"MyForm";
this->Text = L"Foderkalkylator";
this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
(cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->numericSportfit))->EndInit();
this->ResumeLayout(false);
}
Double testVariable = numericSportfit.Value * 14.4;
private: System::Void MyForm_Load(System::Object^ sender, System::EventArgs^ e) {
}
//Button Räkna
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e)
{
MessageBox::Show(testVariable.ToString(), "Resultat");
}
//sportfit numericUpDown
private: System::Void numericSportfit_ValueChanged(System::Object^ sender, System::EventArgs^ e)
{
}
};
}
提前谢谢 如果我理解正确,您的问题在于这一行:
double testVariable = numericSportfit.Value * 14.4;
因此,请查看System::Windows::Forms::NumericUpDown的联机帮助,给出一个显示以下内容的页面
public decimal Value { get; set; }
正如你所说的,只有C。我不记得那个调用的专有名称,但是它取代了C++中的GETValk和StValk等价物。所以我猜可能是getValue或您想要的Value
您应该能够深入到代码中并找到答案,而不是猜测。在您的源代码中,Control单击NumericUpDown,这将带您到定义对象的文件,您可能可以从中找到您需要的内容 另外-你可以在VS2019中编译C,我认为你需要将文件定义为.C文件,但老实说,如果你学习C,你会得到更好的应用程序,IMO。Value应该是->Value