23 Temmuz 2018 Pazartesi

C# PictureBox ile On/Off Switch yapımı

Off Picture
Selamlar
Bunun için birkaç gif ayarladım.


**Off Pic**







On Picture




**On Pic**






Off Gif




 **Off Gif**

On Gif 





**On Gif**






Bunları projenize ekleyin, bir pictureBox ve timer oluşturun
En yukarıya boolean bir değişken tanımlayın adı "onoff" olabilir ve ona false değerini verin
Bu şekilde:


    bool onoff = false;
    int gif1 = 13, gif2 = 13;
    private void Form1_Load(object sender, EventArgs e)
        {         
            timer1.Interval = 100;
         
        }
    private void pictureBox1_Click(object sender, EventArgs e)
        {
            if(!onoff)
            {
                onoff= true;
                pictureBox1.Image = yourproject.Properties.Resources.ongif;
                timer1.Start();
            }
            else
            {
                onoff = false;
                pictureBox1.Image = yourproject.Properties.Resources.offgif;
                timer1.Start();
            }
        }
    private void timer1_Tick(object sender, EventArgs e)
        {
            if(onoff)
            {
                if (gif1 == 0)
                {
                    pictureBox1.Image = yourproject.Properties.Resources.onpic;
                    gif1 = 13;
                    timer1.Stop();
                }
                else
                    gif1--;
            }
            else
            {
                if (gif2 == 0)
                {
                    pictureBox1.Image = yourproject.Properties.Resources.offpic;
                    gif2 = 13;
                    timer1.Stop();
                }
                else
                    gif2--;
            }
        }

Hiç yorum yok:

Yorum Gönder