Linkin_Park

OOP_lab6 Form 3

Nov 2nd, 2017
762
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.54 KB | None | 0 0
  1. #pragma once
  2. #include "RomanFigure.h"
  3. #include <msclr\marshal_cppstd.h>
  4.  
  5.  
  6. namespace OOP_lab6 {
  7.  
  8.     using namespace System;
  9.     using namespace System::ComponentModel;
  10.     using namespace System::Collections;
  11.     using namespace System::Windows::Forms;
  12.     using namespace System::Data;
  13.     using namespace System::Drawing;
  14.     using namespace msclr::interop;
  15.  
  16.     /// <summary>
  17.     /// Summary for MyForm3
  18.     /// </summary>
  19.     public ref class MyForm3 : public System::Windows::Forms::Form
  20.     {
  21.     public:
  22.         MyForm3(void)
  23.         {
  24.             InitializeComponent();
  25.             //
  26.             //TODO: Add the constructor code here
  27.             //
  28.         }
  29.  
  30.     protected:
  31.         /// <summary>
  32.         /// Clean up any resources being used.
  33.         /// </summary>
  34.         ~MyForm3()
  35.         {
  36.             if (components)
  37.             {
  38.                 delete components;
  39.             }
  40.         }
  41.     private: System::Windows::Forms::Label^  label5;
  42.     protected:
  43.  
  44.     private: System::Windows::Forms::RichTextBox^  richTextBox3;
  45.     private: System::Windows::Forms::RichTextBox^  richTextBox2;
  46.     private: System::Windows::Forms::RichTextBox^  richTextBox1;
  47.     private: System::Windows::Forms::Button^  button1;
  48.     private: System::Windows::Forms::Label^  label3;
  49.     private: System::Windows::Forms::Label^  label4;
  50.     private: System::Windows::Forms::Label^  label1;
  51.     private: System::Windows::Forms::Label^  label2;
  52.  
  53.     private:
  54.         /// <summary>
  55.         /// Required designer variable.
  56.         /// </summary>
  57.         System::ComponentModel::Container ^components;
  58.  
  59. #pragma region Windows Form Designer generated code
  60.         /// <summary>
  61.         /// Required method for Designer support - do not modify
  62.         /// the contents of this method with the code editor.
  63.         /// </summary>
  64.         void InitializeComponent(void)
  65.         {
  66.             this->label5 = (gcnew System::Windows::Forms::Label());
  67.             this->richTextBox3 = (gcnew System::Windows::Forms::RichTextBox());
  68.             this->richTextBox2 = (gcnew System::Windows::Forms::RichTextBox());
  69.             this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
  70.             this->button1 = (gcnew System::Windows::Forms::Button());
  71.             this->label3 = (gcnew System::Windows::Forms::Label());
  72.             this->label4 = (gcnew System::Windows::Forms::Label());
  73.             this->label1 = (gcnew System::Windows::Forms::Label());
  74.             this->label2 = (gcnew System::Windows::Forms::Label());
  75.             this->SuspendLayout();
  76.             //
  77.             // label5
  78.             //
  79.             this->label5->AutoSize = true;
  80.             this->label5->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 30));
  81.             this->label5->Location = System::Drawing::Point(509, 38);
  82.             this->label5->Name = L"label5";
  83.             this->label5->Size = System::Drawing::Size(106, 58);
  84.             this->label5->TabIndex = 28;
  85.             this->label5->Text = L"dec";
  86.             //
  87.             // richTextBox3
  88.             //
  89.             this->richTextBox3->Enabled = false;
  90.             this->richTextBox3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20));
  91.             this->richTextBox3->Location = System::Drawing::Point(803, 126);
  92.             this->richTextBox3->Name = L"richTextBox3";
  93.             this->richTextBox3->Size = System::Drawing::Size(257, 51);
  94.             this->richTextBox3->TabIndex = 23;
  95.             this->richTextBox3->Text = L"";
  96.             //
  97.             // richTextBox2
  98.             //
  99.             this->richTextBox2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20));
  100.             this->richTextBox2->Location = System::Drawing::Point(439, 126);
  101.             this->richTextBox2->Name = L"richTextBox2";
  102.             this->richTextBox2->Size = System::Drawing::Size(257, 51);
  103.             this->richTextBox2->TabIndex = 22;
  104.             this->richTextBox2->Text = L"";
  105.             this->richTextBox2->TextChanged += gcnew System::EventHandler(this, &MyForm3::richTextBox2_TextChanged);
  106.             //
  107.             // richTextBox1
  108.             //
  109.             this->richTextBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20));
  110.             this->richTextBox1->Location = System::Drawing::Point(76, 126);
  111.             this->richTextBox1->Name = L"richTextBox1";
  112.             this->richTextBox1->Size = System::Drawing::Size(257, 51);
  113.             this->richTextBox1->TabIndex = 21;
  114.             this->richTextBox1->Text = L"";
  115.             this->richTextBox1->TextChanged += gcnew System::EventHandler(this, &MyForm3::richTextBox1_TextChanged);
  116.             //
  117.             // button1
  118.             //
  119.             this->button1->Location = System::Drawing::Point(465, 427);
  120.             this->button1->Name = L"button1";
  121.             this->button1->Size = System::Drawing::Size(190, 63);
  122.             this->button1->TabIndex = 20;
  123.             this->button1->Text = L"Go back to menu";
  124.             this->button1->UseVisualStyleBackColor = true;
  125.             this->button1->Click += gcnew System::EventHandler(this, &MyForm3::button1_Click);
  126.             //
  127.             // label3
  128.             //
  129.             this->label3->AutoSize = true;
  130.             this->label3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 30));
  131.             this->label3->Location = System::Drawing::Point(158, 38);
  132.             this->label3->Name = L"label3";
  133.             this->label3->Size = System::Drawing::Size(106, 58);
  134.             this->label3->TabIndex = 29;
  135.             this->label3->Text = L"dec";
  136.             //
  137.             // label4
  138.             //
  139.             this->label4->AutoSize = true;
  140.             this->label4->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 30));
  141.             this->label4->Location = System::Drawing::Point(858, 38);
  142.             this->label4->Name = L"label4";
  143.             this->label4->Size = System::Drawing::Size(168, 58);
  144.             this->label4->TabIndex = 30;
  145.             this->label4->Text = L"roman";
  146.             //
  147.             // label1
  148.             //
  149.             this->label1->AutoSize = true;
  150.             this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 30));
  151.             this->label1->Location = System::Drawing::Point(358, 126);
  152.             this->label1->Name = L"label1";
  153.             this->label1->Size = System::Drawing::Size(54, 58);
  154.             this->label1->TabIndex = 33;
  155.             this->label1->Text = L"+";
  156.             //
  157.             // label2
  158.             //
  159.             this->label2->AutoSize = true;
  160.             this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 30));
  161.             this->label2->Location = System::Drawing::Point(720, 126);
  162.             this->label2->Name = L"label2";
  163.             this->label2->Size = System::Drawing::Size(54, 58);
  164.             this->label2->TabIndex = 34;
  165.             this->label2->Text = L"=";
  166.             //
  167.             // MyForm3
  168.             //
  169.             this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
  170.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  171.             this->ClientSize = System::Drawing::Size(1161, 529);
  172.             this->Controls->Add(this->label2);
  173.             this->Controls->Add(this->label1);
  174.             this->Controls->Add(this->label4);
  175.             this->Controls->Add(this->label3);
  176.             this->Controls->Add(this->label5);
  177.             this->Controls->Add(this->richTextBox3);
  178.             this->Controls->Add(this->richTextBox2);
  179.             this->Controls->Add(this->richTextBox1);
  180.             this->Controls->Add(this->button1);
  181.             this->Name = L"MyForm3";
  182.             this->Text = L"Addition";
  183.             this->ResumeLayout(false);
  184.             this->PerformLayout();
  185.  
  186.         }
  187. #pragma endregion
  188.     private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
  189.         this->Hide();
  190.     }
  191.  
  192.     private: bool isAllowed(String^ str)
  193.     {
  194.         String^ allowedChar = "0123456789";
  195.  
  196.         for (int i = 0; i < str->Length; i++) {
  197.             if (!~allowedChar->IndexOf(str[i])) {
  198.                 return false;
  199.             }
  200.         }
  201.  
  202.         return true;
  203.     }
  204.  
  205.     private: void sumUp() {
  206.         String^ text1 = richTextBox1->Text;
  207.         String^ text2 = richTextBox2->Text;
  208.         String^ allowedChar = "0123456789";
  209.  
  210.         if (text1 != "" && isAllowed(text1) && text2 != "" && isAllowed(text2) &&
  211.             int(System::Convert::ToInt32(text1)) + int(System::Convert::ToInt32(text2))) {
  212.             RomanFigure temp = int(System::Convert::ToInt32(text1)) + int(System::Convert::ToInt32(text2));
  213.             richTextBox3->Text = marshal_as<String^>(temp.getRoman());
  214.         }
  215.     }
  216.  
  217.     private: System::Void richTextBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
  218.         sumUp();
  219.     }
  220.  
  221.     private: System::Void richTextBox2_TextChanged(System::Object^  sender, System::EventArgs^  e) {
  222.         sumUp();
  223.     }
  224.     };
  225. }
Advertisement
Add Comment
Please, Sign In to add comment