• Progressbar komponentasi
  • Texnologiyalari va kommunikatsiyalarni rivojlantirish vazirligi toshkent axborot texnologiyalari universiteti




    Download 5,48 Mb.
    Pdf ko'rish
    bet44/53
    Sana21.11.2023
    Hajmi5,48 Mb.
    #102807
    1   ...   40   41   42   43   44   45   46   47   ...   53
    Bog'liq
    Texnologiyalari va kommunikatsiyalarni rivojlantirish vazirligi

    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. 


    85 
    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; 


    86 


    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


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


    88 
    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)


    89 
    timer1->Enabled=
    true
    ;
    else
    timer1->Enabled=
    false
    ;

    }; 

    Progressbar komponentasi 
    Progressbar komponentasi All Windows Forms komponentalar panelida 
    joylashgan. Ushbu komponenta vaqt komponentasi bilan birgalikda ish yuritadi. Bu 
    component jarayonning ko’rstakchini ifoda etadi, shuning uchun siz bu jarayon qay 
    tarzda borayotganiga guvoh bo’lasiz. To’rtburchakli indicator chapdan o’ng tomonga 
    qarab to’ladi. Bu progressbarning xususiyatlari va usullari orqali to’ldiriladi.
    Min va Max xossalari indicator intervali qiymatlarini belgilaydi. 
    Value xossasi indicator intervail ichidagi Min va Max qiymatlarini pozitsiyasini 
    o’zgartiradi. 
    Step xossasi value qiymati uchun kelib chiqishini belgilaydi. 
    Progressbar komponentasining ishini tashkil qilish uchun jarayonning 
    ko’rinishini tashkil qilish uchun timer komponentasidan foydalanish kerak: vaqtni 
    hisoblagichni jarayonning boshidan tashkil qilish kerak (Timer1->Enabled=true;). 
    Value xossasiga 0 qiymat berilishi kerak (ProgressBar1->Value=0;), va qayta 
    ishlovchi tick xodisasiga (ProgressBar1->Value++;) yoziladi. 
    Jarayon yakuniga yetgach, timerni o’chirish va indiaktorni yashirish kerak 
    bo’ladi. ProgressBar1->Visible=false; 
    Progressbarga misol, yuqorida keltirilgan timer komponentasida mavjud. 

    Download 5,48 Mb.
    1   ...   40   41   42   43   44   45   46   47   ...   53




    Download 5,48 Mb.
    Pdf ko'rish

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Texnologiyalari va kommunikatsiyalarni rivojlantirish vazirligi toshkent axborot texnologiyalari universiteti

    Download 5,48 Mb.
    Pdf ko'rish