การบ้าน ครั้งที่ 8

โปรแกรม 12.4

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

        private void label1_Click(object sender, EventArgs e)
        {
            int index = list1.SelectedIndex;
            display.Text = list1.Items[index].ToString();
        }

        private void list2_SelectedIndexChanged(object sender, EventArgs e)
        {
            int index = list2.SelectedIndex;
            display.Text = list2.Items[index].ToString();
        }
    }
}





12.5




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 WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }


        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void listBox_SelectedIndexChanged(object sender, EventArgs e)
        {
           
        }

        private void add_Click(object sender, EventArgs e)
        {
            string str = text.Text; 
                  listBox.Items.Add(str); 
        }
    }
}





12.6

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 WindowsFormsApplication1
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }


        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void listBox_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void add_Click(object sender, EventArgs e)
        {
            string str = text.Text;
            listBox.Items.Add(str);
        }

        private void delete_Click(object sender, EventArgs e)
        {
            int index = listBox.SelectedIndex;
            listBox.Items.RemoveAt(index);
        }

        private void Clear_Click(object sender, EventArgs e)
        {
            listBox.Items.Clear();
        }

        private void number_Click(object sender, EventArgs e)
        {
            MessageBox.Show("The number of items in the list is" + listBox.Items.Count.ToString());
        }
    }
}