Yazı Font Küçült Yazı Font Büyült

CheckedListBox ile Nesne Seçimi  

Bu örnekte çalışma anında CheckedListBox oluşturarak; oluşturulan CheckedListBox da checked=true olan itemi messagebox ta göstereceğiz. Aşağıdaki şekli inceleyin.

Resim1

Şekil 1

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsApplication1
{
    public partial class Form1 : Form
    {
        internal System.Windows.Forms.CheckedListBox clistBox;

        public Form1()
        {

            InitializeComponent();
            this.clistBox = new System.Windows.Forms.CheckedListBox();
            this.SuspendLayout();
          
            this.clistBox.Location = new System.Drawing.Point(8, 8);
            this.clistBox.Name = "clistBox";
            this.clistBox.Size = new System.Drawing.Size(264, 196);
            this.clistBox.TabIndex = 2;
           
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
            this.ClientSize = new System.Drawing.Size(280, 218);
            this.Controls.AddRange(new System.Windows.Forms.Control[] { this.clistBox });
            this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.Name = "ListBoxObjects";
            this.Text = "ListBox Nesne";
            this.Load += new System.EventHandler(this.Form1_Load);
            this.clistBox.DoubleClick += new System.EventHandler(this.lstCustomers_DoubleClick);
            this.ResumeLayout(false);

        }

        private void Form1_Load(object sender, EventArgs e)
        {
            clistBox.Items.Clear();
            clistBox.Items.Add(new Customer("Bahadır", "Şahin", DateTime.Now));
            clistBox.Items.Add(new Customer("Haluk", "Akman", DateTime.Now));
            clistBox.Items.Add(new Customer("Fatih", "Koç", DateTime.Now));
        }
        public class Customer
        {
            public string Ad;
            public string Soyad;
            public DateTime Tarih;

            public Customer()
            { }

            public Customer(string ad, string soyad, DateTime tarih)
            {
                this.Ad = ad;
                this.Soyad = soyad;
                this.Tarih = tarih;
            }

            public override string ToString()
            {
                return Ad + " " + Soyad + " " + Tarih;
            }

        }

        private void lstCustomers_DoubleClick(object sender, EventArgs e)
        {

            {
                MessageBox.Show(Convert.ToString(clistBox.SelectedItem));
            }

         }
    }
}

// Bir sonraki makalede görüşmek üzere. Bahadır ŞAHİN