12 Haziran 2015 Cuma

C# Timer Kullanımı

Bu yayınımızda Timer kontrolü ile yapılmış küçük bir uygulama yapıyoruz. Bunun Yanında Scrollbar kontrolününde kullanım şekli yer almaktadır.






using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace timerKontrolü
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Boolean son = false;
        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Interval = hScrollBar1.Value;
        }
        private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
        {
            timer1.Interval = hScrollBar1.Value;
            if (hScrollBar1.Value == hScrollBar1.Maximum)
            {
                son = true;
            }
        }
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (son == false)
            {
                textBox1.Text = hScrollBar1.Value.ToString();
                if (hScrollBar1.Value == 100)
                {
                    son = true;
                    return;
                }
                hScrollBar1.Value = hScrollBar1.Value + 1;
            }
            else
            {
                textBox1.Text = hScrollBar1.Value.ToString();
                if (hScrollBar1.Value == 1)
                {
                    son = false;
                    return;
                }
                hScrollBar1.Value = hScrollBar1.Value - 1;
            }
            if (hScrollBar1.Value < 30)
                textBox1.BackColor = Color.Yellow;
            else if (hScrollBar1.Value < 50)
                textBox1.BackColor = Color.Pink;
            else if (hScrollBar1.Value < 75)
                textBox1.BackColor = Color.Orange;
            else
                textBox1.BackColor = Color.Red;
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (button1.Text == "Başla")
            {
                button1.Text = "Durdur";
                timer1.Enabled = true;
            }
            else
            {
                button1.Text = "Başla";
                timer1.Enabled = false;
            }
        }
    }
}

Hiç yorum yok: