transfer variables from myform.h to myform.cpp

  • Thread starter Thread starter kavi kalash
  • Start date Start date
K

kavi kalash

Guest
#pragma once

namespace Project7 {

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;
}
}
public: System::Windows::Forms::Label^ Iblheader1;
protected:
public: System::Windows::Forms::Label^ Iblheader2;
public: System::Windows::Forms::Label^ Iblequals;
public: System::Windows::Forms::Label^ Iblheader3;
public: System::Windows::Forms::TextBox^ txtfeet;
public: System::Windows::Forms::TextBox^ txtconvertinches;
public: System::Windows::Forms::TextBox^ txtinches;
public: System::Windows::Forms::Button^ btnconvert;
public: System::Windows::Forms::Button^ btnexit;

public:
/// <summary>
/// Required designer variable.
/// </summary>
System::ComponentModel::Container ^components;

// my variable
public:
int iInches;
int iFeet;
int iconvertsdInches;

#pragma region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
void InitializeComponent(void)
{
this->Iblheader1 = (gcnew System::Windows::Forms::Label());
this->Iblheader2 = (gcnew System::Windows::Forms::Label());
this->Iblequals = (gcnew System::Windows::Forms::Label());
this->Iblheader3 = (gcnew System::Windows::Forms::Label());
this->txtfeet = (gcnew System::Windows::Forms::TextBox());
this->txtconvertinches = (gcnew System::Windows::Forms::TextBox());
this->txtinches = (gcnew System::Windows::Forms::TextBox());
this->btnconvert = (gcnew System::Windows::Forms::Button());
this->btnexit = (gcnew System::Windows::Forms::Button());
this->SuspendLayout();
//
// Iblheader1
//
this->Iblheader1->AutoSize = true;
this->Iblheader1->Location = System::Drawing::Point(41, 37);
this->Iblheader1->Name = L"Iblheader1";
this->Iblheader1->Size = System::Drawing::Size(28, 13);
this->Iblheader1->TabIndex = 0;
this->Iblheader1->Text = L"Feet";
//
// Iblheader2
//
this->Iblheader2->AutoSize = true;
this->Iblheader2->Location = System::Drawing::Point(165, 37);
this->Iblheader2->Name = L"Iblheader2";
this->Iblheader2->Size = System::Drawing::Size(39, 13);
this->Iblheader2->TabIndex = 1;
this->Iblheader2->Text = L"Inches";
//
// Iblequals
//
this->Iblequals->AutoSize = true;
this->Iblequals->Location = System::Drawing::Point(276, 108);
this->Iblequals->Name = L"Iblequals";
this->Iblequals->Size = System::Drawing::Size(13, 13);
this->Iblequals->TabIndex = 2;
this->Iblequals->Text = L"=";
//
// Iblheader3
//
this->Iblheader3->AutoSize = true;
this->Iblheader3->Location = System::Drawing::Point(400, 37);
this->Iblheader3->Name = L"Iblheader3";
this->Iblheader3->Size = System::Drawing::Size(39, 13);
this->Iblheader3->TabIndex = 3;
this->Iblheader3->Text = L"inched";
//
// txtfeet
//
this->txtfeet->Location = System::Drawing::Point(44, 108);
this->txtfeet->Name = L"txtfeet";
this->txtfeet->Size = System::Drawing::Size(26, 20);
this->txtfeet->TabIndex = 4;
this->txtfeet->TextChanged += gcnew System::EventHandler(this, &MyForm::txtfeet_TextChanged);
//
// txtconvertinches
//
this->txtconvertinches->Location = System::Drawing::Point(403, 108);
this->txtconvertinches->Name = L"txtconvertinches";
this->txtconvertinches->Size = System::Drawing::Size(26, 20);
this->txtconvertinches->TabIndex = 5;
//
// txtinches
//
this->txtinches->Location = System::Drawing::Point(158, 108);
this->txtinches->Name = L"txtinches";
this->txtinches->Size = System::Drawing::Size(26, 20);
this->txtinches->TabIndex = 6;
this->txtinches->TextChanged += gcnew System::EventHandler(this, &MyForm::txtinches_TextChanged);
//
// btnconvert
//
this->btnconvert->Location = System::Drawing::Point(74, 216);
this->btnconvert->Name = L"btnconvert";
this->btnconvert->Size = System::Drawing::Size(84, 29);
this->btnconvert->TabIndex = 7;
this->btnconvert->Text = L"Convert";
this->btnconvert->UseVisualStyleBackColor = true;
this->btnconvert->Click += gcnew System::EventHandler(this, &MyForm::btnconvert_Click);
//
// btnexit
//
this->btnexit->Location = System::Drawing::Point(241, 216);
this->btnexit->Name = L"btnexit";
this->btnexit->Size = System::Drawing::Size(84, 29);
this->btnexit->TabIndex = 8;
this->btnexit->Text = L"Exit";
this->btnexit->UseVisualStyleBackColor = true;
this->btnexit->Click += gcnew System::EventHandler(this, &MyForm::btnexit_Click);
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(806, 569);
this->Controls->Add(this->btnexit);
this->Controls->Add(this->btnconvert);
this->Controls->Add(this->txtinches);
this->Controls->Add(this->txtconvertinches);
this->Controls->Add(this->txtfeet);
this->Controls->Add(this->Iblheader3);
this->Controls->Add(this->Iblequals);
this->Controls->Add(this->Iblheader2);
this->Controls->Add(this->Iblheader1);
this->Name = L"MyForm";
this->Text = L"MyForm";
this->ResumeLayout(false);
this->PerformLayout();

}
#pragma endregion
public: System::Void txtfeet_TextChanged(System::Object^ sender, System::EventArgs^ e) {
int iTemp;
if(Int32::TryParse(txtfeet->Text,iTemp))
iFeet=Convert::ToInt32(txtfeet->Text);
else
txtfeet->Text=Convert::ToString(iFeet);
}
public: System::Void txtinches_TextChanged(System::Object^ sender, System::EventArgs^ e) {
int iTemp;
if(Int32::TryParse(txtinches->Text,iTemp))
iInches=Convert::ToInt32(txtinches->Text);
else
txtfeet->Text=Convert::ToString( iInches);
}
public: System::Void btnconvert_Click(System::Object^ sender, System::EventArgs^ e) {

iconvertsdInches=(iFeet*12)+iInches;
txtconvertinches->Text=Convert::ToString(iconvertsdInches);

}
public: System::Void btnexit_Click(System::Object^ sender, System::EventArgs^ e) {
}
};
}



#include "MyForm.h"
#include<windows.h>
#include<iostream>
#include"stdio.h"
#include<math.h>
#include<conio.h>
#include<string.h>
#include<iomanip>
#include<fstream>
#include<stdlib.h>
using namespace System;
using namespace System::Windows::Forms;
using namespace std;
[STAThread]
void main(array<String^>^ args) {
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
Project7::MyForm form;
Application::Run(%form);

}



exaple codes of myform.h and myform.cpp as shown in above

Purpose to convert feet to feet+inches to inches

i want to call ifeet and iInches in myform.cpp so how do i call it??

please help...

Continue reading...
 
Back
Top