Calculation Rectangle


#pragma once

namespace My10 {
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::TextBox^ txtRectangleWidth;
private: System::Windows::Forms::Button^ BtnResult;
protected:
protected:
private: System::Windows::Forms::TextBox^ txtRectangleLong;
private: System::Windows::Forms::Label^ lbl;
private: System::Windows::Forms::Label^ label1;
private: System::Windows::Forms::Label^ label2;
private: System::Windows::Forms::PictureBox^ pctResult;

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->txtRectangleWidth = (gcnew System::Windows::Forms::TextBox());
this->BtnResult = (gcnew System::Windows::Forms::Button());
this->txtRectangleLong = (gcnew System::Windows::Forms::TextBox());
this->lbl = (gcnew System::Windows::Forms::Label());
this->label1 = (gcnew System::Windows::Forms::Label());
this->label2 = (gcnew System::Windows::Forms::Label());
this->pctResult = (gcnew System::Windows::Forms::PictureBox());
(cli::safe_cast
(this->pctResult))->BeginInit();
this->SuspendLayout();
//
// txtRectangleWidth
//
this->txtRectangleWidth->Location = System::Drawing::Point(58, 59);
this->txtRectangleWidth->Name = L"txtRectangleWidth";
this->txtRectangleWidth->Size = System::Drawing::Size(202, 20);
this->txtRectangleWidth->TabIndex = 0;
//
// BtnResult
//
this->BtnResult->Location = System::Drawing::Point(58, 152);
this->BtnResult->Name = L"BtnResult";
this->BtnResult->Size = System::Drawing::Size(202, 86);
this->BtnResult->TabIndex = 1;
this->BtnResult->Text = L"Show Result";
this->BtnResult->UseVisualStyleBackColor = true;
this->BtnResult->Click += gcnew System::EventHandler(this, &Form1::BtnResult_Click);
//
// txtRectangleLong
//
this->txtRectangleLong->Location = System::Drawing::Point(58, 106);
this->txtRectangleLong->Name = L"txtRectangleLong";
this->txtRectangleLong->Size = System::Drawing::Size(202, 20);
this->txtRectangleLong->TabIndex = 2;
//
// lbl
//
this->lbl->AutoSize = true;
this->lbl->Location = System::Drawing::Point(103, 20);
this->lbl->Name = L"lbl";
this->lbl->Size = System::Drawing::Size(90, 13);
this->lbl->TabIndex = 3;
this->lbl->Text = L": Width X Long";
//
// label1
//
this->label1->AutoSize = true;
this->label1->Location = System::Drawing::Point(12, 59);
this->label1->Name = L"label1";
this->label1->Size = System::Drawing::Size(44, 13);
this->label1->TabIndex = 4;
this->label1->Text = L"Width : ";
//
// label2
//
this->label2->AutoSize = true;
this->label2->Location = System::Drawing::Point(12, 109);
this->label2->Name = L"label2";
this->label2->Size = System::Drawing::Size(40, 13);
this->label2->TabIndex = 5;
this->label2->Text = L"Long : ";
//
// pctResult
//
this->pctResult->BorderStyle = System::Windows::Forms::BorderStyle::Fixed3D;
this->pctResult->Location = System::Drawing::Point(273, 8);
this->pctResult->Name = L"pctResult";
this->pctResult->Size = System::Drawing::Size(420, 242);
this->pctResult->TabIndex = 6;
this->pctResult->TabStop = false;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(705, 263);
this->Controls->Add(this->pctResult);
this->Controls->Add(this->label2);
this->Controls->Add(this->label1);
this->Controls->Add(this->lbl);
this->Controls->Add(this->txtRectangleLong);
this->Controls->Add(this->BtnResult);
this->Controls->Add(this->txtRectangleWidth);
this->Name = L"Form1";
this->Text = L"Calculation Rectangle";
this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
(cli::safe_cast
(this->pctResult))->EndInit();
this->ResumeLayout(false);
this->PerformLayout();
}
#pragma endregion
//Calculation a Rectangle
// Width X Long
double RectangleWidth;
double RectangleLong;
double CalculationRectangle()
{
double RectangleResult;
RectangleWidth=System::Convert::ToDouble(txtRectangleWidth->Text);
RectangleLong=System::Convert::ToDouble(txtRectangleLong->Text);
//Width X Long
RectangleResult=RectangleWidth*RectangleLong;
// Return Value
return RectangleResult;
}
void DrawCalRectangle(Graphics^RectangleGraphics,int RectangleX,
int RectangleY,int RectangleWidth,int RectangleHeight)
{
Pen^HPen;
HPen=gcnew Pen(Color::Black,1);
HPen->DashStyle=System::Drawing::Drawing2D::DashStyle::Dot;
RectangleGraphics->DrawRectangle(HPen,RectangleX,
RectangleY,RectangleWidth,RectangleHeight);
}
private: System::Void BtnResult_Click(System::Object^ sender, System::EventArgs^ e) {
double ReCalRectangle;
ReCalRectangle=CalculationRectangle();
this->Text="Width = "+RectangleWidth+
" Long = " +RectangleLong+ " = "+
ReCalRectangle;
Graphics^RecGraphics;
RecGraphics=pctResult->CreateGraphics();
RecGraphics->Clear(pctResult->BackColor);
DrawCalRectangle(RecGraphics,10,
10,RectangleWidth,RectangleLong);
}
private: System::Void Form1_Load(System::Object^ sender, System::EventArgs^ e) {
pctResult->BackColor=System::Drawing::Color::White;
this->BackColor=System::Drawing::Color::Yellow;
this->Text="Calculation Rectangle";
this->MaximizeBox=false;
}
};
}