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 8847065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:07:39+00:00 2026-06-14T12:07:39+00:00

I have custom control which is derived from PictureBox control. I wanna write a

  • 0

I have custom control which is derived from PictureBox control. I wanna write a KeyDown Event for it and I’ve written the code below and still I’m not being able to use it. Please check my code below and instruct me if I’m doing anything wrong or any more additions are required. I know there is no by default KeyDown event for PictureBox and so I’m trying to make a custom Select-able PictureBox with KeyDown Event…

    using System;
    using System.Linq;
    using System.Windows.Forms;

    namespace BenisImageDownloader
    {
        class SelectablePictureBox:PictureBox
        {
            public SelectablePictureBox()
            {
                this.SetStyle(ControlStyles.Selectable, true);
                this.TabStop = true;
            }

            protected override void OnMouseDown(MouseEventArgs e)
            {
                this.Focus();
                base.OnMouseDown(e);
            }

            protected override void OnKeyDown(KeyEventArgs e)
            {
                if (e.KeyCode == Keys.Up || e.KeyCode == Keys.Down || e.KeyCode == Keys.Left || e.KeyCode == Keys.Right)
                    e.Handled = true;
                base.OnKeyDown(e);
            }

            protected override bool IsInputKey(Keys keyData)
            {
                if (keyData == Keys.Up || keyData == Keys.Down) return true;
                if (keyData == Keys.Left || keyData == Keys.Right) return true;
                return base.IsInputKey(keyData);
            }

            protected override void OnEnter(EventArgs e)
            {
                this.Invalidate();
                base.OnEnter(e);
            }

            protected override void OnLeave(EventArgs e)
            {
                this.Invalidate();
                base.OnLeave(e);
            }

            protected override void OnPaint(PaintEventArgs pe)
            {
                base.OnPaint(pe);
                if (this.Focused)
                {
                    var rc = this.ClientRectangle;
                    rc.Inflate(-2, -2);
                    ControlPaint.DrawFocusRectangle(pe.Graphics, rc);
                }
            }
        }
    }

I’m a student working on Windows Form Application v4.0 project(not WPF) for my papers to be submitted.

  • 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-14T12:07:40+00:00Added an answer on June 14, 2026 at 12:07 pm

    You can override the control’s ProcessCmdKey() function instead and capture the key-presses there.

    (sorry, I only have a VB example – but you’ll get the idea):

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message,
                                               ByVal keyData As System.Windows.Forms.Keys) As Boolean
    
        'process key, return true for processed
        If (keyData And Keys.KeyCode) = Keys.KeyToCheck Then
            Return true
        End If
    
        Return MyBase.ProcessCmdKey(msg, keyData)
    
    End Function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written a custom server control which (pseudo-code) looks like public class MyCustomCtrl
I have a class derived from slider which uses a custom control template and
I have my own custom control derived from System.Windows.Forms.TreeView which is present on the
I have created a custom control which derives from Panel. I use it to
I have a class derived from TreeviewItem(Custom TreeViewItem) which is used by a class
I have a custom control which needs to configure a MultiBinding in code, which
I have a custom control: it's managed code, which subclasses System.Windows.Forms.Control. I want to
I am working on a custom wpf control which is derived from a ListBox
I have a custom control which displays results of some operations. It is hidden
I have a custom server control which wraps a RadEditor (basically a textarea). I

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.