How to check if the Shift key is pressed in KeyDown and using WinForms with C#

2 Answers

0 votes
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Modifiers == Keys.Shift)
            {
                MessageBox.Show("Shift is pressed");
            }
        }
    }
}




/*
run:

Shift is pressed

*/

 



answered Mar 25, 2024 by avibootz
0 votes
namespace WinFormsApp1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            if ((ModifierKeys & Keys.Shift) == Keys.Shift)
            {
                MessageBox.Show("Shift is pressed");
            }
        }
    }
}




/*
run:

Shift is pressed

*/

 



answered Mar 25, 2024 by avibootz
...