• 02-01-2014, 11:09:46
    #1
    Üyeliği durduruldu
    Merhabalar , c#'da bu uygulamayı yapmam gerekiyor. 2 adet label olucak biri dakika biri saniyeyi göstericek. Girdiğim dakika ve saniyeden geri saymaya başlıcak. Bittiğindede uyarı vericek.

    Elimde aşağıdaki kodlar var ama Visual Studio'da Windows Form Application olarak açıyorum kodları yazdığımda

    The name 'timer1' does not exist in the current context
    The name 'label3' does not exist in the current context
    The name 'label1' does not exist in the current context

    gibi hatalar veriyor. Yardımcı olabilirseniz çok sevinirim.

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace saat
    {
        public partial class Form1 : Form
        {
            int b = 60;
            int a;
            public Form1()
            {
                InitializeComponent();
            }
    
            private void timer1_Tick(object sender, EventArgs e)
            {
                timer1.Interval =1000;
    
                
                if (a != 0)
                {
                    b = b - 1;
                    label3.Text = Convert.ToString(b);
                    label1.Text = Convert.ToString(a-1);
                    if (b == 0)
                    {  
                  
                       a = a - 1;  label1.Text = Convert.ToString(a);
                     b = 59;
                    }
               
                }
                if (a == 0)
                {   timer1.Stop();
                    MessageBox.Show("merhaba");
                    
                }
    
                
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                
                a = Convert.ToInt32(textBox1.Text); ;
    
                timer1.Start();
    
            }
    
      
        }
    }
  • 02-01-2014, 11:14:25
    #2
    kodu bir yerden mi kopyaladın acaba ?

    The name 'timer1' does not exist in the current context
    The name 'label3' does not exist in the current context
    The name 'label1' does not exist in the current context

    bunlar formun üzerinde yok yada name leri farklı yani aldığın hatalar bununla alakalı
  • 02-01-2014, 11:16:20
    #3
    Üyeliği durduruldu
    devveloper adlı üyeden alıntı: mesajı görüntüle
    kodu bir yerden mi kopyaladın acaba ?

    The name 'timer1' does not exist in the current context
    The name 'label3' does not exist in the current context
    The name 'label1' does not exist in the current context

    bunlar formun üzerinde yok yada name leri farklı yani aldığın hatalar bununla alakalı
    evet yapan bi arkadaşım gönderdi kodları ordan kopyaladım nasıl düzeltebilirim bu hatayı veya bu uygulamayı nasıl yapabilirim?
  • 02-01-2014, 11:18:18
    #4
    design kısmına geç oraya 2 tane label koy birisinin ismi label3 diğerinin ki de label1 olsun, sonra bir tane de timer koy adı timer1 olsun ondan sonra çalıştırmayı dene
  • 02-01-2014, 11:43:17
    #5
    Üyeliği durduruldu
    Hatalar düzeldi ama geri sayım yapmıyor. Yardım eden birisi olursa çok sevinirim. 14.00'a kadar yapmam gerekiyor.
  • 02-01-2014, 14:08:38
    #6
    Merhaba,

    Olası hata yakalama işlemlerini de içeren ufak bir uygulama örneği yazdım.

    Yapmanız gereken formunuza 2 adet label(zorunlu değil, görsel açıdan dakika ve saniye kutucuklarını isimlendirmek için), 2 adet textbox, 1 adet buton ve 1 adet timer koymanızdır.

     public partial class Form1 : Form
        {
            int dakika;
            int saniye;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                try
                {
                    if (textBox1.Text == string.Empty && textBox2.Text == string.Empty)
                    {
                        MessageBox.Show("Dakika ve saniye alanları boş bırakılamaz");
    
                    }
    
                    if (textBox1.Text == string.Empty && textBox2.Text != string.Empty)
                    {
                        MessageBox.Show("Dakika alanı boş bırakılamaz");
    
                    }
    
                    if (textBox1.Text != string.Empty && textBox2.Text == string.Empty)
                    {
                        MessageBox.Show("Saniye alanı boş bırakılamaz");
    
                    }
    
                    if (textBox1.Text != string.Empty && textBox2.Text != string.Empty)
                    {
                        if (int.Parse(textBox1.Text) == 0 && int.Parse(textBox2.Text) == 0)
                            MessageBox.Show("Geri sayım için uygun değerler kullanmıyorsunuz");
                    }
    
                    if (textBox1.Text != string.Empty && textBox2.Text != string.Empty)
                    {
                        if (int.Parse(textBox1.Text) >= 0 && int.Parse(textBox2.Text) <= 59 && int.Parse(textBox2.Text) != 0)
                        {
                            textBox1.ReadOnly = true;
                            textBox2.ReadOnly = true;
                            button1.Enabled = false;
    
                            dakika = int.Parse(textBox1.Text);
                            saniye = int.Parse(textBox2.Text);
    
                            timer1.Interval = 1000;
                            timer1.Tick += new EventHandler(timer1_Tick);
                            timer1.Start();
                        }
                    }
    
                    if (textBox1.Text != string.Empty && textBox2.Text != string.Empty)
                    {
                        if (int.Parse(textBox1.Text) >= 0 && int.Parse(textBox2.Text) > 59)
                            MessageBox.Show("Saniyede yanlış değer kullanıyorsunuz");
                    }
                }
    
                catch (Exception ex)
                {
                    MessageBox.Show("Sadece sayısal değer girebilirsiniz");
                    textBox1.Text = string.Empty;
                    textBox2.Text = string.Empty;
                }
            }
            void timer1_Tick(object sender, EventArgs e)
            {
                if (dakika > 0 && saniye == 0)
                {
                    dakika--;
                    saniye = 60;
    
                    textBox1.Text = dakika.ToString();
                }
                if (dakika > 0 && saniye <=60 && saniye != 0)
                {
                    saniye--;
    
                    textBox2.Text = saniye.ToString();
                }
                if (dakika == 0 && saniye <= 60 && saniye != 0)
                {
                    saniye--;
    
                    textBox2.Text = saniye.ToString();
                }
    
                if (dakika == 0 && saniye == 0)
                {
                    timer1.Stop();
                    MessageBox.Show("Geri sayım bitti.");
                    Application.Restart();
                    
                    
                }
                
            }
        }
    Teşekkürler.
  • 02-01-2014, 14:13:33
    #7
    Üyeliği durduruldu
    anx adlı üyeden alıntı: mesajı görüntüle
    Merhaba,

    Olası hata yakalama işlemlerini de içeren ufak bir uygulama örneği yazdım.

    Yapmanız gereken formunuza 2 adet label(zorunlu değil, görsel açıdan dakika ve saniye kutucuklarını isimlendirmek için), 2 adet textbox ve 1 adet buton koymanızdır.

     public partial class Form1 : Form
        {
            int dakika;
            int saniye;
    
            public Form1()
            {
                InitializeComponent();
            }
    
            private void button1_Click(object sender, EventArgs e)
            {
                try
                {
                    if (textBox1.Text == string.Empty && textBox2.Text == string.Empty)
                    {
                        MessageBox.Show("Dakika ve saniye alanları boş bırakılamaz");
    
                    }
    
                    if (textBox1.Text == string.Empty && textBox2.Text != string.Empty)
                    {
                        MessageBox.Show("Dakika alanı boş bırakılamaz");
    
                    }
    
                    if (textBox1.Text != string.Empty && textBox2.Text == string.Empty)
                    {
                        MessageBox.Show("Saniye alanı boş bırakılamaz");
    
                    }
    
                    if (textBox1.Text != string.Empty && textBox2.Text != string.Empty)
                    {
                        if (int.Parse(textBox1.Text) == 0 && int.Parse(textBox2.Text) == 0)
                            MessageBox.Show("Geri sayım için uygun değerler kullanmıyorsunuz");
                    }
    
                    if (textBox1.Text != string.Empty && textBox2.Text != string.Empty)
                    {
                        if (int.Parse(textBox1.Text) >= 0 && int.Parse(textBox2.Text) <= 59 && int.Parse(textBox2.Text) != 0)
                        {
                            textBox1.ReadOnly = true;
                            textBox2.ReadOnly = true;
                            button1.Enabled = false;
    
                            dakika = int.Parse(textBox1.Text);
                            saniye = int.Parse(textBox2.Text);
    
                            timer1.Interval = 1000;
                            timer1.Tick += new EventHandler(timer1_Tick);
                            timer1.Start();
                        }
                    }
    
                    if (textBox1.Text != string.Empty && textBox2.Text != string.Empty)
                    {
                        if (int.Parse(textBox1.Text) >= 0 && int.Parse(textBox2.Text) > 59)
                            MessageBox.Show("Saniyede yanlış değer kullanıyorsunuz");
                    }
                }
    
                catch (Exception ex)
                {
                    MessageBox.Show("Sadece sayısal değer girebilirsiniz");
                    textBox1.Text = string.Empty;
                    textBox2.Text = string.Empty;
                }
            }
            void timer1_Tick(object sender, EventArgs e)
            {
                if (dakika > 0 && saniye == 0)
                {
                    dakika--;
                    saniye = 60;
    
                    textBox1.Text = dakika.ToString();
                }
                if (dakika > 0 && saniye <=60 && saniye != 0)
                {
                    saniye--;
    
                    textBox2.Text = saniye.ToString();
                }
                if (dakika == 0 && saniye <= 60 && saniye != 0)
                {
                    saniye--;
    
                    textBox2.Text = saniye.ToString();
                }
    
                if (dakika == 0 && saniye == 0)
                {
                    timer1.Stop();
                    MessageBox.Show("Geri sayım bitti.");
                    Application.Restart();
                    
                    
                }
                
            }
        }
    Teşekkürler.

    Çok teşekkür ederim konu kilitlenebilir.