C# CheckBox Kullanımı Örnek - Bilişim Konuları

C# CheckBox Kullanımı Örnek

Bu yazımızda Visual C# programında checkBox nesnesinin kullanımı ile ilgili bir örnek yapacağız. Örneğimizde herhangi bir cafede kullanılabilecek bir sipariş fişi hazırlıyoruz. Program için forma 5 tane checkBox nesnesi bir tanede textBox nesnesi ekliyoruz. Hesapla butonuna aşağıdaki kodu yazarak programı bitiriyoruz. checkbox nesnesinin checked özelliğinden faydalanarak işaretlenen siparişlerin toplam fiyatını otomatik olarak hesaplatıp textbox nesnesine yazdırıyoruz.

Programın Ekran Görüntüleri:

csharp-checkbox-ornegi-1

csharp-checkbox-ornegi-2

Programın Visual C# kodları:

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 checkbox_kullanımı_3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            int tutar=0;
            if (checkBox1.Checked)
            {
                tutar = tutar + 1;
            }
            if (checkBox2.Checked)
            {
                tutar = tutar + 5;
            }
            if (checkBox3.Checked)
            {
                tutar = tutar + 7;
            }
            if (checkBox4.Checked)
            {
                tutar = tutar + 6;
            }
            if (checkBox5.Checked)
            {
                tutar = tutar + 3;
            }
            textBox1.Text = tutar.ToString();
        }
    }
}
Bu Yazıya Tepkin Nedir?
+1
1
+1
0
+1
0
+1
1
+1
0
+1
0
+1
0

Yorum Yap