winfrom ListBox 使用 点击弹窗

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 ToUpdateGasStationMis.练习
{
    public partial class FrmDemo : Form
    {
        public FrmDemo()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 显示listBox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            this.listBox1.Items.Clear();
            this.listBox1.Items.Add("软件部");
            this.listBox1.Items.Add("测试部");
            this.listBox1.Items.Add("采购部");
            this.listBox1.Items.Add("销售部");
            this.listBox1.Items.Add("人事部");

        }
        /// <summary>
        /// 添加ListBox
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                listBox1.Items.Insert(2, "插入值");
                label1.Text = "已添加" + listBox1.Items.Count.ToString() + "记录条数";
            }
            catch (Exception ex )
            {

            }
            
        }
        /// <summary>
        /// ListBox 点击弹窗
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            MessageBox.Show("您选择的部门是:"+listBox1.SelectedItem.ToString()+"位列第"+listBox1.SelectedIndex.ToString(),"信息提示!");
        }
        /// <summary>
        /// 打开加载    
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FrmDemo_Load(object sender, EventArgs e)
        {
            this.comboBox1.Items.Add("a1");
            this.comboBox1.Items.Add("a2");
            this.comboBox1.Items.Add("a3");
            this.comboBox1.Items.Add("a4");
            this.comboBox1.Items.Add("a5");
            this.comboBox1.Items.Add("a6");
            this.comboBox1.Items.Add("a7");

        }
    }
}

发布了134 篇原创文章 · 获赞 13 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/qq_36074218/article/details/103277149