
#pragma once
namespace My11 {
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 for Form1
///
/// WARNING: If you change the name of this class, you will need to change the
/// 'Resource File Name' property for the managed resource compiler tool
/// associated with all .resx files this class depends on. Otherwise,
/// the designers will not be able to interact properly with localized
/// resources associated with this form.
///
public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}
protected:
///
/// Clean up any resources being used.
///
~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Button^ BtnResult;
private: System::Windows::Forms::TextBox^ txtSide2;
protected:
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::PictureBox^ pctResult;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::Label^ label3;
private: System::Windows::Forms::TextBox^ txtSide1;
protected:
private:
///
/// Required designer variable.
///
System::ComponentModel::Container ^components;
#pragma region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
void InitializeComponent(void)
{
this->BtnResult = (gcnew System::Windows::Forms::Button());
this->txtSide2 = (gcnew System::Windows::Forms::TextBox());
this->label1 = (gcnew System::Windows::Forms::Label());
this->pctResult = (gcnew System::Windows::Forms::PictureBox());
this->label2 = (gcnew System::Windows::Forms::Label());
this->label3 = (gcnew System::Windows::Forms::Label());
this->txtSide1 = (gcnew System::Windows::Forms::TextBox());
(cli::safe_cast
this->SuspendLayout();
//
// BtnResult
//
this->BtnResult->Location = System::Drawing::Point(61, 166);
this->BtnResult->Name = L"BtnResult";
this->BtnResult->Size = System::Drawing::Size(238, 92);
this->BtnResult->TabIndex = 0;
this->BtnResult->Text = L"Show Result";
this->BtnResult->UseVisualStyleBackColor = true;
this->BtnResult->Click += gcnew System::EventHandler(this, &Form1::BtnResult_Click);
//
// txtSide2
//
this->txtSide2->Location = System::Drawing::Point(61, 109);
this->txtSide2->Name = L"txtSide2";
this->txtSide2->Size = System::Drawing::Size(238, 20);
this->txtSide2->TabIndex = 1;
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(136, 26);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(68, 13);
this->label1->TabIndex = 2;
this->label1->Text = L"Side X Side";
//
// pctResult
//
this->pctResult->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
this->pctResult->Location = System::Drawing::Point(316, 12);
this->pctResult->Name = L"pctResult";
this->pctResult->Size = System::Drawing::Size(440, 242);
this->pctResult->TabIndex = 3;
this->pctResult->TabStop = false;
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(12, 70);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(40, 13);
this->label2->TabIndex = 4;
this->label2->Text = L"Side1 :";
//
// label3
//
this->label3->AutoSize = true;
this->label3->Location = System::Drawing::Point(12, 112);
this->label3->Name = L"label3";
this->label3->Size = System::Drawing::Size(43, 13);
this->label3->TabIndex = 5;
this->label3->Text = L"Side2 :";
//
// txtSide1
//
this->txtSide1->Location = System::Drawing::Point(61, 67);
this->txtSide1->Name = L"txtSide1";
this->txtSide1->Size = System::Drawing::Size(238, 20);
this->txtSide1->TabIndex = 6;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(768, 273);
this->Controls->Add(this->txtSide1);
this->Controls->Add(this->label3);
this->Controls->Add(this->label2);
this->Controls->Add(this->pctResult);
this->Controls->Add(this->label1);
this->Controls->Add(this->txtSide2);
this->Controls->Add(this->BtnResult);
this->Name = L"Form1";
this->Text = L"Form1";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
(cli::safe_cast
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
//Calculation Square
double SquareSide1;
double SquareSide2;
Graphics^SquareGraphics;
Pen^HPen;
double ResultCalSquare()
{
double ReSquare;
SquareSide1=System::Convert::ToDouble(txtSide1->Text);
SquareSide2=System::Convert::ToDouble(txtSide2->Text);
ReSquare=SquareSide1*SquareSide2;
return ReSquare;
}
void DrawSquare()
{
HPen=gcnew Pen(Color::Blue,1);
HPen->DashStyle=System::Drawing::Drawing2D::DashStyle::Dot;
SquareGraphics->DrawRectangle(HPen,10,10,SquareSide1,SquareSide2);
}
private: System::Void BtnResult_Click(System::Object^ sender, System::EventArgs^ e) {
ResultCalSquare();
this->Text="Side1 : "+SquareSide1+" X "+"Side2 : "+
SquareSide2+" = "+ResultCalSquare();
SquareGraphics=pctResult->CreateGraphics();
SquareGraphics->Clear(pctResult->BackColor);
DrawSquare();
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
this->Text="Calculation Square";
this->BackColor=System::Drawing::Color::Aqua;
pctResult->BackColor=System::Drawing::Color::White;
}
};
}