Sharof rashidov nomidagi samarqand davlat universiteti intelektual tizimlar va innvation tizimlar fakulteti dasturiy injinirngi yo


Download 80.4 Kb.
bet3/4
Sana03.02.2023
Hajmi80.4 Kb.
#1154024
1   2   3   4
Bog'liq
Javohir Achilov Labaratoriya

3-Topshiriq.
Masala sharti: (3)Sutka boshidan beri N sekund o’tdi. Sutka boshidan necha to’liq minut o’tganini chiqaruvchi dastur dastur tuzing. (1 ta Label, 1 ta TextBox, 1 ta Button. Natija Labelda chiqarilsin))


Dasturning visual ko’rinishi.

Dastur kodi:
#pragma once

namespace vaqniolcha {


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 MyForm
///

public ref class MyForm : public System::Windows::Forms::Form
{
public:
MyForm(void)
{
InitializeComponent();
//
//TODO: Add the constructor code here
//
}

protected:


///
/// Clean up any resources being used.
///

~MyForm()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::TextBox^ textBox1;
protected:

protected:


private: System::Windows::Forms::Button^ button1;


private: System::Windows::Forms::Label^ S;

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->textBox1 = (gcnew System::Windows::Forms::TextBox());
this->button1 = (gcnew System::Windows::Forms::Button());
this->S = (gcnew System::Windows::Forms::Label());
this->SuspendLayout();
//
// textBox1
//
this->textBox1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 15.75F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast(0)));
this->textBox1->Location = System::Drawing::Point(33, 25);
this->textBox1->Name = L"textBox1";
this->textBox1->Size = System::Drawing::Size(148, 31);
this->textBox1->TabIndex = 6;
this->textBox1->TextAlign = System::Windows::Forms::HorizontalAlignment::Center;
this->textBox1->KeyPress += gcnew System::Windows::Forms::KeyPressEventHandler(this, &MyForm::textBox1_KeyPress);
//
// button1
//
this->button1->BackColor = System::Drawing::Color::Cyan;
this->button1->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 12, System::Drawing::FontStyle::Bold, System::Drawing::GraphicsUnit::Point,
static_cast(0)));
this->button1->Location = System::Drawing::Point(45, 93);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(114, 35);
this->button1->TabIndex = 7;
this->button1->Text = L"Hisoblash";
this->button1->UseVisualStyleBackColor = false;
this->button1->Click += gcnew System::EventHandler(this, &MyForm::button1_Click);
//
// S
//
this->S->AutoSize = true;
this->S->Font = (gcnew System::Drawing::Font(L"Microsoft Sans Serif", 14.25F, System::Drawing::FontStyle::Regular, System::Drawing::GraphicsUnit::Point,
static_cast(0)));
this->S->Location = System::Drawing::Point(65, 167);
this->S->Name = L"S";
this->S->Size = System::Drawing::Size(61, 24);
this->S->TabIndex = 8;
this->S->Text = L"Natija:";
//
// MyForm
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->BackColor = System::Drawing::Color::Silver;
this->ClientSize = System::Drawing::Size(210, 219);
this->Controls->Add(this->S);
this->Controls->Add(this->button1);
this->Controls->Add(this->textBox1);
this->Name = L"MyForm";
this->Text = L"MyForm";
this->ResumeLayout(false);
this->PerformLayout();

}
#pragma endregion


private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
int n;
if (textBox1->Text == "") {
DateTime^t = DateTime::Now;
n = Convert::ToInt16(t->Hour) * 60 + Convert::ToInt16(t->Minute);
if (n > 0) {
S->Text = "Natija:" + Convert::ToString(n);
}
else MessageBox::Show("Qiymat noto'g'ri kiritildi!", "Xatolik", MessageBoxButtons::OK, MessageBoxIcon::Error);

}
else {


n = Convert::ToInt16(textBox1->Text);
if (n > 0) {
n = n / 60;
S->Text = "Natija:" + Convert::ToString(n);
}
else MessageBox::Show("Qiymat noto'g'ri kiritildi!", "Xatolik", MessageBoxButtons::OK, MessageBoxIcon::Error);

}

}


private: System::Void textBox1_KeyPress(System::Object^ sender, System::Windows::Forms::KeyPressEventArgs^ e) {
if (e->KeyChar == '.') {
if (this->textBox1->Text->Contains(".") && !this->textBox1->SelectedText->Contains("."))
e->Handled = true;
}
// Allow negative numbers
else if (e->KeyChar == '-' && !(this->textBox1->Text->Contains("-"))) {
e->Handled = true;
textBox1->Text = "-" + textBox1->Text;
}
// Accept only digits ".", "-" and the Backspace character
else if (!Char::IsDigit(e->KeyChar) && e->KeyChar != 0x08) {
e->Handled = true;
}
}
};
}


Download 80.4 Kb.

Do'stlaringiz bilan baham:
1   2   3   4




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling