peterzig

[C++] Timer CLR

May 18th, 2020
1,957
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 9.05 KB | None | 0 0
  1. #pragma once
  2. #include <cstdio>
  3. #include <ctime>
  4. #include <cstdlib>
  5.  
  6. using namespace std;
  7.  
  8.  
  9. namespace CppCLRWinformsProjekt {
  10.  
  11.     using namespace System;
  12.     using namespace System::ComponentModel;
  13.     using namespace System::Collections;
  14.     using namespace System::Windows::Forms;
  15.     using namespace System::Data;
  16.     using namespace System::Drawing;
  17.  
  18.     int _ticks;
  19.  
  20.     public ref class Form1 : public System::Windows::Forms::Form
  21.     {
  22.     public:
  23.         Form1(void)
  24.         {
  25.             InitializeComponent();
  26.            
  27.         }
  28.  
  29.     protected:
  30.    
  31.         ~Form1()
  32.         {
  33.             if (components)
  34.             {
  35.                 delete components;
  36.             }
  37.         }
  38.     private: System::Windows::Forms::MenuStrip^ menuStrip1;
  39.     protected:
  40.     private: System::Windows::Forms::ToolStripMenuItem^ wybórZadaniaToolStripMenuItem;
  41.     private: System::Windows::Forms::ToolStripMenuItem^ zadanie6ToolStripMenuItem;
  42.     private: System::Windows::Forms::ToolStripMenuItem^ zadanie8ToolStripMenuItem;
  43.     private: System::Windows::Forms::ColorDialog^ colorDialog1;
  44.     private: System::Windows::Forms::TextBox^ textBox1;
  45.     private: System::Windows::Forms::Button^ button1;
  46.  
  47.     private: System::Windows::Forms::Button^ button2;
  48.     private: System::Windows::Forms::Button^ button3;
  49.     private: System::Windows::Forms::PictureBox^ pictureBox1;
  50.     private: System::Windows::Forms::Timer^ timer1;
  51.     private: System::ComponentModel::IContainer^ components;
  52.  
  53.  
  54.  
  55.  
  56.  
  57.     protected:
  58.  
  59.  
  60.     private:
  61.        
  62.  
  63.  
  64. #pragma region Windows Form Designer generated code
  65.    
  66.         void InitializeComponent(void)
  67.         {
  68.             this->components = (gcnew System::ComponentModel::Container());
  69.             this->menuStrip1 = (gcnew System::Windows::Forms::MenuStrip());
  70.             this->wybórZadaniaToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  71.             this->zadanie6ToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  72.             this->zadanie8ToolStripMenuItem = (gcnew System::Windows::Forms::ToolStripMenuItem());
  73.             this->colorDialog1 = (gcnew System::Windows::Forms::ColorDialog());
  74.             this->textBox1 = (gcnew System::Windows::Forms::TextBox());
  75.             this->button1 = (gcnew System::Windows::Forms::Button());
  76.             this->button2 = (gcnew System::Windows::Forms::Button());
  77.             this->button3 = (gcnew System::Windows::Forms::Button());
  78.             this->pictureBox1 = (gcnew System::Windows::Forms::PictureBox());
  79.             this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
  80.             this->menuStrip1->SuspendLayout();
  81.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->BeginInit();
  82.             this->SuspendLayout();
  83.             //
  84.             // menuStrip1
  85.             //
  86.             this->menuStrip1->GripMargin = System::Windows::Forms::Padding(2, 2, 0, 2);
  87.             this->menuStrip1->ImageScalingSize = System::Drawing::Size(24, 24);
  88.             this->menuStrip1->Items->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(1) { this->wybórZadaniaToolStripMenuItem });
  89.             this->menuStrip1->Location = System::Drawing::Point(0, 0);
  90.             this->menuStrip1->Name = L"menuStrip1";
  91.             this->menuStrip1->Size = System::Drawing::Size(986, 36);
  92.             this->menuStrip1->TabIndex = 2;
  93.             this->menuStrip1->Text = L"menuStrip1";
  94.             //
  95.             // wybórZadaniaToolStripMenuItem
  96.             //
  97.             this->wybórZadaniaToolStripMenuItem->DropDownItems->AddRange(gcnew cli::array< System::Windows::Forms::ToolStripItem^  >(2) {
  98.                 this->zadanie6ToolStripMenuItem,
  99.                     this->zadanie8ToolStripMenuItem
  100.             });
  101.             this->wybórZadaniaToolStripMenuItem->Name = L"wybórZadaniaToolStripMenuItem";
  102.             this->wybórZadaniaToolStripMenuItem->Size = System::Drawing::Size(147, 32);
  103.             this->wybórZadaniaToolStripMenuItem->Text = L"Wybór zadania";
  104.             this->wybórZadaniaToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::wybórZadaniaToolStripMenuItem_Click);
  105.             //
  106.             // zadanie6ToolStripMenuItem
  107.             //
  108.             this->zadanie6ToolStripMenuItem->Name = L"zadanie6ToolStripMenuItem";
  109.             this->zadanie6ToolStripMenuItem->Size = System::Drawing::Size(191, 34);
  110.             this->zadanie6ToolStripMenuItem->Text = L"Zadanie 6";
  111.             this->zadanie6ToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::zadanie6ToolStripMenuItem_Click);
  112.             //
  113.             // zadanie8ToolStripMenuItem
  114.             //
  115.             this->zadanie8ToolStripMenuItem->Name = L"zadanie8ToolStripMenuItem";
  116.             this->zadanie8ToolStripMenuItem->Size = System::Drawing::Size(191, 34);
  117.             this->zadanie8ToolStripMenuItem->Text = L"Zadanie 8";
  118.             this->zadanie8ToolStripMenuItem->Click += gcnew System::EventHandler(this, &Form1::zadanie8ToolStripMenuItem_Click);
  119.             //
  120.             // colorDialog1
  121.             //
  122.             this->colorDialog1->AnyColor = true;
  123.             //
  124.             // textBox1
  125.             //
  126.             this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
  127.                 static_cast<System::Byte>(238)));
  128.             this->textBox1->Location = System::Drawing::Point(318, 163);
  129.             this->textBox1->Name = L"textBox1";
  130.             this->textBox1->Size = System::Drawing::Size(294, 35);
  131.             this->textBox1->TabIndex = 3;
  132.             this->textBox1->Visible = false;
  133.             //
  134.             // button1
  135.             //
  136.             this->button1->Location = System::Drawing::Point(318, 226);
  137.             this->button1->Name = L"button1";
  138.             this->button1->Size = System::Drawing::Size(294, 103);
  139.             this->button1->TabIndex = 4;
  140.             this->button1->Text = L"Zmień kolor tekstu";
  141.             this->button1->UseVisualStyleBackColor = true;
  142.             this->button1->Visible = false;
  143.             this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
  144.             //
  145.             // button2
  146.             //
  147.             this->button2->Location = System::Drawing::Point(318, 89);
  148.             this->button2->Name = L"button2";
  149.             this->button2->Size = System::Drawing::Size(140, 46);
  150.             this->button2->TabIndex = 6;
  151.             this->button2->Text = L"Start";
  152.             this->button2->UseVisualStyleBackColor = true;
  153.             this->button2->Visible = false;
  154.             this->button2->Click += gcnew System::EventHandler(this, &Form1::button2_Click);
  155.             //
  156.             // button3
  157.             //
  158.             this->button3->Location = System::Drawing::Point(472, 89);
  159.             this->button3->Name = L"button3";
  160.             this->button3->Size = System::Drawing::Size(140, 46);
  161.             this->button3->TabIndex = 7;
  162.             this->button3->Text = L"Stop";
  163.             this->button3->UseVisualStyleBackColor = true;
  164.             this->button3->Visible = false;
  165.             this->button3->Click += gcnew System::EventHandler(this, &Form1::button3_Click);
  166.             //
  167.             // pictureBox1
  168.             //
  169.             this->pictureBox1->ImageLocation = L"nyan1.bmp";
  170.             this->pictureBox1->Location = System::Drawing::Point(318, 163);
  171.             this->pictureBox1->Margin = System::Windows::Forms::Padding(4, 5, 4, 5);
  172.             this->pictureBox1->Name = L"pictureBox1";
  173.             this->pictureBox1->Size = System::Drawing::Size(319, 200);
  174.             this->pictureBox1->SizeMode = System::Windows::Forms::PictureBoxSizeMode::AutoSize;
  175.             this->pictureBox1->TabIndex = 8;
  176.             this->pictureBox1->TabStop = false;
  177.             this->pictureBox1->Visible = false;
  178.             //
  179.             // timer1
  180.             //
  181.             this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
  182.             //
  183.             // Form1
  184.             //
  185.             this->AutoScaleDimensions = System::Drawing::SizeF(9, 20);
  186.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  187.             this->ClientSize = System::Drawing::Size(986, 528);
  188.             this->Controls->Add(this->pictureBox1);
  189.             this->Controls->Add(this->button3);
  190.             this->Controls->Add(this->button2);
  191.             this->Controls->Add(this->button1);
  192.             this->Controls->Add(this->textBox1);
  193.             this->Controls->Add(this->menuStrip1);
  194.             this->MainMenuStrip = this->menuStrip1;
  195.             this->Name = L"Form1";
  196.             this->Text = L"Timer Zuzanna Prościak";
  197.             this->menuStrip1->ResumeLayout(false);
  198.             this->menuStrip1->PerformLayout();
  199.             (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->pictureBox1))->EndInit();
  200.             this->ResumeLayout(false);
  201.             this->PerformLayout();
  202.  
  203.         }
  204. #pragma endregion
  205.     private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
  206.         if (colorDialog1->ShowDialog() != System::Windows::Forms::DialogResult::Cancel) {
  207.             textBox1->ForeColor = colorDialog1->Color;
  208.         }
  209.     }
  210. private: System::Void zadanie6ToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  211.     textBox1->Visible = true;
  212.     button1->Visible = true;
  213.     button2->Visible = false;
  214.     button3->Visible = false;
  215.     pictureBox1->Visible = false;
  216. }
  217. private: System::Void zadanie8ToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  218.     textBox1->Visible = false;
  219.     button1->Visible = false;
  220.     button2->Visible = true;
  221.     button3->Visible = true;
  222.     pictureBox1->Visible = true;
  223. }
  224. private: System::Void wybórZadaniaToolStripMenuItem_Click(System::Object^ sender, System::EventArgs^ e) {
  225. }
  226. private: System::Void button2_Click(System::Object^ sender, System::EventArgs^ e) {
  227.     timer1->Enabled = true;
  228.     timer1->Interval = 1000;
  229.     timer1->Start();
  230. }
  231. private: System::Void button3_Click(System::Object^ sender, System::EventArgs^ e) {
  232.     timer1->Enabled = false;
  233.     pictureBox1->ImageLocation = "nyan1.bmp";
  234. }
  235. private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
  236.     _ticks++;
  237.     if (_ticks % 2 == 0) {
  238.         pictureBox1->ImageLocation = "nyan2.bmp";
  239.     }
  240.     else
  241.     {
  242.         pictureBox1->ImageLocation = "nyan1.bmp";
  243.     }
  244. }
  245. };
  246. }
Advertisement
Add Comment
Please, Sign In to add comment