Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8425627
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T04:19:26+00:00 2026-06-10T04:19:26+00:00

I am working on a CustomControl and I want to register ModifierKeys in this

  • 0

I am working on a CustomControl and I want to register ModifierKeys in this control. I have already set the KeyPerview to True in the Form which this control is being added to.

Now I have a Boolean named _ctrl and I want this boolean to be true when the Control key is being held down and it should be false when Control key is being released.

I tried to achive this with the conde belowe in my CustomControl but no success!

private bool _ctrl = false;

private void MyCustomControl_KeyDown(object sender, KeyEventArgs e)
{
    if(e.KeyCode == Keys.Control)
    {
        _ctrl = true;
    }
}

private void MyCustomControl_KeyUp(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Control)
    {
        _ctrl = false;
    }
}

Any tips/soloution will be appriciated!

UPDATE

Ok, I decided to do the key down and up event in the form itself:

        private void MainForm_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Modifiers == Keys.Control)
        {
            projectBrowser.ControlKeyIsDown = true; //bool in MyCustomControl
            MessageBox.Show("CTRL is PRESSED");
        } 
     }

    private void MainForm_KeyUp(object sender, KeyEventArgs e)
    {
        if (e.Modifiers == Keys.Control)
        {
            projectBrowser.ControlKeyIsDown = false; //bool in MyCustomControl
            MessageBox.Show("CTRL is DEPRESSED");
        } 
    }

Now, The KeyDown event detects the control key and messagebox is being shown. But the KeyUp event does not work and it doesn’t show the messagebox. What could be wrong?

It seems that the key up gets detected if I change the KeyUpevent like this:

private void MainForm_KeyUp(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.LControlKey || e.KeyCode == Keys.RControlKey || e.KeyCode == Keys.ControlKey || e.KeyCode == Keys.Control)
    {
        projectBrowser.ControlKeyIsDown = false;
        e.Handled = true;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T04:19:27+00:00Added an answer on June 10, 2026 at 4:19 am

    You can try calling the Control.ModifierKeys property:

    protected override void OnKeyDown(KeyEventArgs e) {
      if (Control.ModifierKeys == Keys.Control) {
        MessageBox.Show("I am pressing control.");
      }
      base.OnKeyDown(e);
    }
    

    If you throw up a MessageBox on the KeyDown event, the KeyUp event won’t get called.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on a custom control and have created a property in property
I'm working on Expression Blend and I'm currently designing a custom control which has
I am working on a custom control which draws curves on it and allows
I'm working on an form custom control.the control is a MonthCalendar like Visual studio(C#)
I have a Windows::Forms application and I want to add a custom control to
I am working on a custom control for WPF and Silverlight. This control has
I have a custom container control (deriving from FlowLayoutPanel ) which contains zero or
I have built a custom control that extends content control. Within this I have
I have custom control where i want to show some items. In generic.xaml defined
I have made one custom user control (search text box), which basically consists of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.