【问题标题】:C# GUI Keyboard shortcutsC# GUI 键盘快捷键
【发布时间】:2018-06-21 16:06:02
【问题描述】:

Checked_List_Box

(这就是我选中的列表框的样子^)

我想实现键盘快捷键Ctrl + Shift + Click, 在checked_list_box 中。目前我的代码看起来像这样,有什么想法可以从哪里开始吗?

我想要的结果是,当我通过鼠标单击选择框中的一个选项时,Ctrl + Shift + Click 将选择其余文件,直到我单击的下一个选项。

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;
using System.IO;

namespace SelectFiles
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            checkedListBox1.CheckOnClick = true;
        }

    private void button1_Click(object sender, EventArgs e)
    {
        FolderBrowserDialog fbd = new FolderBrowserDialog();
        if (fbd.ShowDialog() == System.Windows.Forms.DialogResult.OK)
        {
            MessageBox.Show(fbd.SelectedPath);
            checkedListBox1.Items.Clear();
            string[] files = Directory.GetFiles(fbd.SelectedPath);

            foreach (string file in files)
            {
                checkedListBox1.Items.Add(file);
            }
        }
    private void button2_Click_1(object sender, EventArgs e)
    {
        List<string> list_all_excelfiles = new List<string>();
        foreach (string item in checkedListBox1.CheckedItems)
        {
            list_all_excelfiles.Add(item);
            MessageBox.Show(Path.GetFileName(item));
        }
    }
}

【问题讨论】:

标签: c# winforms user-interface


【解决方案1】:

您可以在点击事件中使用 Form.ModifierKeys 来实现这一点

private void checkedListBox1_MouseClick(object sender, MouseEventArgs e)
{
    if (Form.ModifierKeys.HasFlag(Keys.Control) && Form.ModifierKeys.HasFlag(Keys.Shift))
    {
        //Do something
    }
}

【讨论】:

    猜你喜欢
    • 2011-04-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多