Linkin_Park

OOP_lab6 Form 1

Nov 2nd, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.04 KB | None | 0 0
  1. #pragma once
  2. #include "RomanFigure.h"
  3. #include <msclr\marshal_cppstd.h>
  4.  
  5. namespace OOP_lab6 {
  6.  
  7.     using namespace System;
  8.     using namespace System::ComponentModel;
  9.     using namespace System::Collections;
  10.     using namespace System::Windows::Forms;
  11.     using namespace System::Data;
  12.     using namespace System::Drawing;
  13.     using namespace msclr::interop;
  14.  
  15.     /// <summary>
  16.     /// Summary for MyForm1
  17.     /// </summary>
  18.     public ref class MyForm1 : public System::Windows::Forms::Form
  19.     {
  20.     public:
  21.         MyForm1(void)
  22.         {
  23.             InitializeComponent();
  24.             //
  25.             //TODO: Add the constructor code here
  26.             //
  27.         }
  28.  
  29.     protected:
  30.         /// <summary>
  31.         /// Clean up any resources being used.
  32.         /// </summary>
  33.         ~MyForm1()
  34.         {
  35.             if (components)
  36.             {
  37.                 delete components;
  38.             }
  39.         }
  40.     private: System::Windows::Forms::Button^  button1;
  41.     protected:
  42.     private: System::Windows::Forms::Label^  label2;
  43.     private: System::Windows::Forms::Label^  label1;
  44.     private: System::Windows::Forms::RichTextBox^  richTextBox3;
  45.     private: System::Windows::Forms::RichTextBox^  richTextBox1;
  46.  
  47.     private:
  48.         /// <summary>
  49.         /// Required designer variable.
  50.         /// </summary>
  51.         System::ComponentModel::Container ^components;
  52.  
  53. #pragma region Windows Form Designer generated code
  54.         /// <summary>
  55.         /// Required method for Designer support - do not modify
  56.         /// the contents of this method with the code editor.
  57.         /// </summary>
  58.         void InitializeComponent(void)
  59.         {
  60.             this->button1 = (gcnew System::Windows::Forms::Button());
  61.             this->label2 = (gcnew System::Windows::Forms::Label());
  62.             this->label1 = (gcnew System::Windows::Forms::Label());
  63.             this->richTextBox3 = (gcnew System::Windows::Forms::RichTextBox());
  64.             this->richTextBox1 = (gcnew System::Windows::Forms::RichTextBox());
  65.             this->SuspendLayout();
  66.             //
  67.             // button1
  68.             //
  69.             this->button1->Location = System::Drawing::Point(478, 437);
  70.             this->button1->Name = L"button1";
  71.             this->button1->Size = System::Drawing::Size(190, 63);
  72.             this->button1->TabIndex = 10;
  73.             this->button1->Text = L"Go back to menu";
  74.             this->button1->UseVisualStyleBackColor = true;
  75.             this->button1->Click += gcnew System::EventHandler(this, &MyForm1::button1_Click);
  76.             //
  77.             // label2
  78.             //
  79.             this->label2->AutoSize = true;
  80.             this->label2->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 30));
  81.             this->label2->Location = System::Drawing::Point(322, 239);
  82.             this->label2->Name = L"label2";
  83.             this->label2->Size = System::Drawing::Size(516, 58);
  84.             this->label2->TabIndex = 9;
  85.             this->label2->Text = L"Output roman number";
  86.             //
  87.             // label1
  88.             //
  89.             this->label1->AutoSize = true;
  90.             this->label1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 30));
  91.             this->label1->Location = System::Drawing::Point(374, 29);
  92.             this->label1->Name = L"label1";
  93.             this->label1->Size = System::Drawing::Size(415, 58);
  94.             this->label1->TabIndex = 8;
  95.             this->label1->Text = L"Input dec number";
  96.             //
  97.             // richTextBox3
  98.             //
  99.             this->richTextBox3->Enabled = false;
  100.             this->richTextBox3->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20));
  101.             this->richTextBox3->Location = System::Drawing::Point(408, 329);
  102.             this->richTextBox3->Name = L"richTextBox3";
  103.             this->richTextBox3->Size = System::Drawing::Size(342, 51);
  104.             this->richTextBox3->TabIndex = 7;
  105.             this->richTextBox3->Text = L"";
  106.             //
  107.             // richTextBox1
  108.             //
  109.             this->richTextBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 20));
  110.             this->richTextBox1->Location = System::Drawing::Point(408, 119);
  111.             this->richTextBox1->Name = L"richTextBox1";
  112.             this->richTextBox1->Size = System::Drawing::Size(342, 51);
  113.             this->richTextBox1->TabIndex = 6;
  114.             this->richTextBox1->Text = L"";
  115.             this->richTextBox1->TextChanged += gcnew System::EventHandler(this, &MyForm1::richTextBox1_TextChanged);
  116.             //
  117.             // MyForm1
  118.             //
  119.             this->AutoScaleDimensions = System::Drawing::SizeF(8, 16);
  120.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  121.             this->ClientSize = System::Drawing::Size(1161, 529);
  122.             this->Controls->Add(this->button1);
  123.             this->Controls->Add(this->label2);
  124.             this->Controls->Add(this->label1);
  125.             this->Controls->Add(this->richTextBox3);
  126.             this->Controls->Add(this->richTextBox1);
  127.             this->Name = L"MyForm1";
  128.             this->Text = L"Dec To Roman";
  129.             this->ResumeLayout(false);
  130.             this->PerformLayout();
  131.  
  132.         }
  133. #pragma endregion
  134.     private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
  135.         this->Hide();
  136.     }
  137.  
  138.     private: bool isAllowed(String^ str)
  139.     {
  140.         String^ allowedChar = "0123456789";
  141.  
  142.         for (int i = 0; i < str->Length; i++) {
  143.             if (!~allowedChar->IndexOf(str[i])) {
  144.                 return false;
  145.             }
  146.         }
  147.  
  148.         return true;
  149.     }
  150.  
  151.     private: System::Void richTextBox1_TextChanged(System::Object^  sender, System::EventArgs^  e) {
  152.         String^ text = richTextBox1->Text;
  153.         String^ allowedChar = "0123456789";
  154.  
  155.         if (text != "" && isAllowed(text)) {
  156.             RomanFigure temp(int(System::Convert::ToInt32(text)));
  157.             richTextBox3->Text = marshal_as<String^>(temp.getRoman());
  158.         }
  159.     }
  160. };
  161. }
Advertisement
Add Comment
Please, Sign In to add comment