当前位置:网站首页>C (XXIX) C listbox CheckedListBox Imagelist

C (XXIX) C listbox CheckedListBox Imagelist

2022-07-06 03:47:00 camellias_

listBox attribute :

Items: All options

SelectionMode: Whether to support multiple selection

(1):one You can only choose one

(2):Multisimple Multiple choices available

(3):MultExtended Press the key combination to select more

(4):none There is no choice

Multicolnum:

true: Support horizontal arrangement

false: Horizontal arrangement is not supported

SelectedIndex

listbox The index of the option is from 0 At the beginning of the alignment .

Checklistbox

Items: All options

CheckOnClick

False: You need to double-click to select the option

True: Click to select the option

Imagelist Components

Images:

Set of pictures in the component Use an array to represent

[ Failed to transfer the external chain picture , The origin station may have anti-theft chain mechanism , It is suggested to save the pictures and upload them directly (img-CBeNjYHK-1655864764074)(https://p3-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/d545a3c973ff45d0b1eb310cb4b34549~tplv-k3u1fbpfcp-zoom-1.image "1555393498465220.png")]

The test uses all the code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace _0416Day
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void putButton_Click(object sender, EventArgs e)
        {
            int index = listBox1.SelectedIndex;
            if(index == 0)
            {
                result.Text = listBox1.SelectedItem.ToString();
            }
            else if(index == 1)
            {
                result.Text = listBox1.SelectedItem.ToString();
            }
            else if (index == 2)
            {
                result.Text = listBox1.SelectedItem.ToString();
            }
            else
            {
                MessageBox.Show(" Please choose the option ");
            }
        }
        /**
         *  Add a button 
         */
        private void Add_Click(object sender, EventArgs e)
        {
            listBox1.Items.Add(Input.Text);
            Input.Clear();
        }
 
        /**
         *  Remove button 
         */
        private void Remove_Click(object sender, EventArgs e)
        {
            int sel = listBox1.SelectedIndex;
            if (sel != -1)
            {
                listBox1.Items.RemoveAt(listBox1.SelectedIndex);
            }
            else
            {
                MessageBox.Show(" Please select the option you want to remove ");
            }
        }
 
        /**
         *  Clear button 
         */
        private void Clear_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
        }
 
        /**
         *  Check box default event 
         *  Check the text to execute ( Don't modify CheckOnClick You need to double-click to check the attribute )
         */
        private void fubox_SelectedIndexChanged(object sender, EventArgs e)
        {
 
        }
 
        /**
         *  Check box default event 
         *  Select the text ( Don't tick ) Will execute 
         */
        private void fubox_ItemCheck(object sender, ItemCheckEventArgs e)
        {
            // e It's a parameter object , Equal to the selected value 
            if (e.NewValue == CheckState.Checked)
            {
                //  Selected primary key ( Select to display the picture )
                switch (e.Index)
                {
                    case 0: pictureBox1.Image = imageList1.Images[0]; break;
                    case 1: pictureBox2.Image = imageList1.Images[1]; break;
                    case 2: pictureBox3.Image = imageList1.Images[2]; break;
                    case 3: pictureBox4.Image = imageList1.Images[3]; break;
                }
            }
            else
            {
                //  Unselected primary key ( After removing the selection, the picture disappears )
                switch (e.Index)
                {
                    case 0: pictureBox1.Image = null; break;
                    case 1: pictureBox2.Image = null; break;
                    case 2: pictureBox3.Image = null; break;
                    case 3: pictureBox4.Image = null; break;
                }
            }
        }
 
    }
}

There are good suggestions , Please enter your comments below .

Welcome to personal blog
https://guanchao.site

Welcome to the applet :

 Insert picture description here

原网站

版权声明
本文为[camellias_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060338512057.html