//in your main form, this is how you instantiate your new class and access its members private: System::Void btnAdd_Click(System::Object^ sender, System::EventArgs^ e) { //---instantiate the DoMath class DoMath^ myCalculator = gcnew DoMath(); //---assign values to the properties after making sure the data is double precision! double num1=0; double num2 =0; if(Double::TryParse(txtFirst->Text,num1) && Double::TryParse(txtSecond->Text, num2)) { myCalculator->FirstNumber =num1; myCalculator->SecondNumber=num2; double answer = myCalculator->AddThem(); //call the functions txtResult->Text = answer.ToString(); //display the result } else { MessageBox::Show("Please enter numbers only.", "System Message", MessageBoxButtons::OK, MessageBoxIcon::Error); ClearForm(); } } //_____________________________________________DoMath Class I add to the project #pragma once #include "Form1.h" // make sure to reference the form where we will be calling this class from using namespace System; using namespace System::Windows::Forms; // so we can use messagebox //make sure the class is public. It is created as private by default! public ref class DoMath sealed //sealed means this class cannot be inherited and saves a bit of processing so use it! { public: DoMath(void) { } //---Create two fields for our properties static double _number1= 0; static double _number2 = 0; public: property double FirstNumber { double get() { return _number1; } void set (double value) { if(FirstNumber >=0) _number1 = value; } } public: property double SecondNumber { double get() { return _number2; } void set (double value) { if(SecondNumber >= 0) _number2 = value; } } public: double AddThem() { if (FirstNumber >= 0 && SecondNumber >= 0) { return FirstNumber + SecondNumber; } }