⏩ OldSchoolKO ✅ | " VALHALLA " 2.000.000 TL ÖDÜL ⭐ 3 YIL ARADAN SONRA ✅ v.1098 MYKO EFSANESİ ⚔ OFFICIAL 17.05.2024 - 21:00 ⏪
Cuceko

C# sistem saati yapımı

  •         

            

            

            

            

  • HyperFilter | DoS Protection | DDoS Protection | DoS Mitigation | DDoS Mitigation | AntiDoS | AntiDDoS | Proxy Shielding
S Çevrimdışı

saintx

Kayıtlı Üye
12 Mart 2012
250
0
18
28
Merhaba arkadaşlar,



Bugün sizlerle sistem saati yapacağız.Bu işlemler için bir adet windows form projesi oluşturalım.

Formumuzun içerisine bir adet sınıf (class) ekliyelim ve sınıfmızın(class) ismini timeClass yapalım.

Tekrar formumuza dönerek bir adet label ve timer ekliyelim.İsimlerini ise tmrTime, lblTime şeklinde değiştirelim.

Bu işlemleri yaptıktan sonra sınıfımıza(class) dönerek şu kodları ekleyelim.



Kod:
using System;

using System.Collections.Generic;

using System.Text;



namespace sistem_saati_sinifi

{

    class sistemsaati

    {

        public static int s1, s2, s3;

        public static string saatiGetir(string second, string minute, string hour)

        {

            s1 = Convert.ToInt32(second);

            s2 = Convert.ToInt32(minute);

            s3 = Convert.ToInt32(hour);

            s1++;

            if (s1 == 60)

            {

                s2++;

                s1 = 0;

            }

            if (s2 == 60)

            {

                s3++;

                s2 = 0;

                s1 = 0;

            }

            if (s3 == 24)

            {

                s1 = 0;

                s2 = 0;

                s3 = 0;

            }

            if (s1 < 10)

            {

                second = "0" + second;

            }

            if (s2 < 10)

            {

                minute = "0" + minute;

            }

            if (s3 < 10)

            {

                hour = "0" + hour;

            }

            return hour + "." + minute + "." + second;

        }

    }

}



Tekrar formumuza dönerek tmrTime isimli timerimizin Interval özelliğini 1000 millisaniye yapalım.



Kullanılacak sınıf (kütüphane) ;

Kod:
using sistem_saati_sinifi;



Bu işlemleri yaptıktan sonra formumuzda bulunan tmrTime isimli timerimizin tick olayına şu kodları ekleyelim.



Kod:
this.lblTime.Text = saintx.getTime(DateTime.Now.Second.ToString(), DateTime.Now.Minute.ToString(), DateTime.Now.Hour.ToString());



En son olarak tüm işlemleri tamamladıktan sonra formumuzun açılış olayına (form load) şu kodları ekleyelim.



Kod:
this.tmrTime.Start();



iyi çalışmalar ~ saintx