I've been trying out the windows forms for a small project of mine where the program calculates the contents of different amounts of food.
I figured the NumericUpDowns would be a good way to get inputs on the amount of food.
I tried following Microsofts tutorials on how to get the value from an NumericUpDown for the calculations and ended up with this:
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");
}
However I keep getting the error message "E0153 expression must have class type" and "C2228 left of '.Value' must have class/struct/union"
I am running VS 2019. I have tried searching the entire web for on how to get the value in C++ but all I can find is C#. Originally I just wanted to program in C as that is what I'm most familiar with but seems VS only has C++ and C#.
Here is the entire block of code:
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)
{
}
};
}
.Valueshould be->Value