Amaliy ish №13 Mavzu: Visual C++ning grafik imkoniyatlari. Grafik holat, tasvirlarni va funksiya grafiklarini qurish. Chart komponentalari Combobox, Picturebox, Timer va Progressbar komponentalari Ishni bajarishdan maqsad


Download 0.57 Mb.
bet3/4
Sana17.06.2023
Hajmi0.57 Mb.
#1535785
1   2   3   4
Bog'liq
13-amaliyot , Dasturlash II

Timer komponentasi
Timer komponentasi All Windows Forms komponentalar panelida joylashgan. Uning vazifasi vaqtni hisoblash.
Timerning Enabled xossassi Timerni ishga tushirish va uni to’xtatishni boshqaradi.
Timerning yana bir xossasi bo’lmish Interval, vaqt oralig’ini ifodalash uchun xizmat qiladi, ya’ni biron bir buyruqni bajarishda vaqt intervali, shu buyruqni qancha milli sekunddan keyin boshlashni ko’rib chiqadi, bunda 1000 millisekund 1 sekundga to’g’ri kelsa, intervalning odatiy xolati 100 millisekundda turadi.
Komponentaning asosiy metodi bu start() va stop() bo’lib, u timer vaqtini boshlaydi va tugatadi.
Timerning faqatgina bitta xodisasi mavjud, u tick xodisasi.
Timerning qanday ishlashini o’rganish maqsadida quyidagi dasturni o’rganish lozim:
Timer, button, progressbar komponentalarini tanlaymiz va formga joylaymiz.
Ushbu dastur to’liq ishga tushishi uchun lozim bo’lgan kutubxonani qo’shishimiz lozim ya’ni #include bu kutubxona random funksiyasini ishlatish uchun, ushbu funksia esa istalgan qiymatni berish uchun ishlatiladi.

Dasturning kodi quyida keltirilgan:
#pragma once
#include
namespace WindowsFormsApplication2 {
using namespace System;
using namespace System::ComponentModel;
using namespace System::Collections;
using namespace System::Windows::Forms;
using namespace System::Data;
using namespace System::Drawing;
///
///

public ref class Form1 : public System::Windows::Forms::Form
{
public:
Form1(void)
{
InitializeComponent();
//
//TODO: konstruktor kodini qo’shish
//
}
protected:
///
/// barcha foydalaniladigan resurslarni tozalash.
///

~Form1()
{
if (components)
{
delete components;
}
}
private: System::Windows::Forms::Timer^ timer1;
protected:
private: System::Windows::Forms::Button^ button1;
private: System::Windows::Forms::ProgressBar^ progressBar1;
private: System::ComponentModel::IContainer^ components;
private:
///
/// O’zgaruvchan konstruktor talab qilinadi.
///

#pragma region Windows Form Designer generated code
///
///

void InitializeComponent(void)
{
this->components = (gcnew System::ComponentModel::Container());
this->timer1 = (gcnew System::Windows::Forms::Timer(this->components));
this->button1 = (gcnew System::Windows::Forms::Button());
this->progressBar1 = (gcnew System::Windows::Forms::ProgressBar());
this->SuspendLayout();
//
// timer1
//
this->timer1->Tick += gcnew System::EventHandler(this, &Form1::timer1_Tick);
//
// button1
//
this->button1->Location = System::Drawing::Point(24, 14);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(79, 52);
this->button1->TabIndex = 0;
this->button1->Text = L"Vaqtni boshlash/to\'xtatish";
this->button1->UseVisualStyleBackColor = true;
this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
//
// progressBar1
//
this->progressBar1->Location = System::Drawing::Point(24, 72);
this->progressBar1->Name = L"progressBar1";
this->progressBar1->Size = System::Drawing::Size(100, 23);
this->progressBar1->TabIndex = 1;
//
// Form1
//
this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
this->ClientSize = System::Drawing::Size(284, 262);
this->Controls->Add(this->progressBar1);
this->Controls->Add(this->button1);
this->Name = L"Form1";
this->Text = L"Form1";
this->ResumeLayout(false);
}
#pragma endregion
private: System::Void timer1_Tick(System::Object^ sender, System::EventArgs^ e) {
Color ^col = gcnew Color();
Pen ^pen = gcnew Pen(col->Black);
Graphics ^im = this->CreateGraphics();
int x1,x2,y1,y2;
x1=rand(); //tasodifiy sonni olish uchun funksiya
x2=rand();
y1=rand();
y2=rand();
pen->Width=5;
if(x1 > 200)
x1=200-(x1%200);
pen->Color=Color::FromArgb(x1);
if(x2 > 200)
x2=200-(x2%200);
if(y1 > 200)
y1=200-(y1%200);
if(y2 > 200)
y2=200-(y2%200);
pen->Color=Color::FromArgb(x1,x2,y1,y2);
im->DrawLine(pen,x1,y1,x2,y2);
if (progressBar1->Value!='100'){
this->progressBar1->Value++;
}else timer1->Enabled=false;
}
private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
this->progressBar1->Value=0;
//timerni yoqish/o’chirish
if(!timer1->Enabled)
timer1->Enabled=true;
else
timer1->Enabled=false;
}
};
}

Download 0.57 Mb.

Do'stlaringiz bilan baham:
1   2   3   4




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