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

  • SEARCH
  • Home
  • 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 210205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T17:59:04+00:00 2026-05-11T17:59:04+00:00

If I do not create an Edit->Copy menu item and assign it the shortcut

  • 0

If I do not create an “Edit->Copy” menu item and assign it the shortcut keys “CTRL+C”, then I can select a control (RichTextBox, DataGridView, etc..) and hit “CTRL+C” and the control itself will handle the copy. I can copy text out, and paste it into notepad, etc..

Now throughout my whole form, I have a lot of controls. But I have a custom control that I want to make clear that I handle Copy functionality for. So I added the ShortcutKey CTRL+C to Edit->Copy, and by default it is set to Enabled.

Now, I have to implement an event handler for the ‘click’ event on that menu item. If I explicitly put in code to handle the copy, then it works:

public void menuEditCopy_Click(object sender, EventArgs e)
{
    myCustomControl.Copy();
}

However, now Copy does not work on any other type of control. My first inclination was to find out the type of control that has focus, and implement a limited set of copy code for each of them:

public void menuEditCopy_Click(object sender, EventArgs e)
{
    if (this.ActiveControl is MyCustomControl)
    {
        ((MyCustomControl)this.ActiveControl).Copy();
    }
    else if (this.ActiveControl is RichTextBox)
    {
        ((RichTextBox)this.ActiveControl).Copy();
    }
}

etc…

However, my controls are added to a SplitContainer, and debugging shows that this.ActiveControl is set to the splitcontainer instance, not the control, even though I know that control is selected.

So my last thought is to literally check if every control has focus:

public void menuEditCopy_Click(object sender, EventArgs e)
{
    if (myCustomControl.Focused)
    {
        myCustomControl.Copy();
    }
    else if (richTextBox1.Focused)
    {
        richTextBox1.Copy();
    }
}

I would like to avoid this if possible, it is a lot of controls, and if I add a new control, I would need to update it. Is there a better way of doing this?

Thanks

  • 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-05-11T17:59:04+00:00Added an answer on May 11, 2026 at 5:59 pm

    A SplitContainer implements ContainerControl, so you could check for either one and look for it’s ActiveControl instead. ContainerControl is the base class, so I would go for that – you might catch another type of container as well:

    private void DoCopy(Control control)
    {
        if(control is ContainerControl)
            DoCopy(control.SelectedControl);
        else if(control is MyCustomControl)
            ((MyCustomControl)control).Copy();
        else if(control is RichTextBox)
            ((RichTextBox)control).Copy();
        else
            throw new NotSupportedException("The selected control can't copy!");
    }
    
    void menuEditCopy_Click(object sender, EventArgs e)
    {
        DoCopy(this.ActiveControl);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Since DirectedSparseGraph implements serializable ( javadoc ), why can I not create a graph,
I create a new Django app (not project) called Bussinesses, then add following class
I can create a contact that is not mail enabled, but how do I
Here's the deal. I can create a ListBox and style it. I can edit
I need to create a text editing control in C# and I'm not sure
Is it possible to make lein uberjar not create a jar if no changes
The following code does not always create the file. As far as I noticed,
I am not looking to create new events. I need to create a canvas
I am not able to create a jsTree inside of a jQuery UI tab.
If it is not possible to create this list without loops, I'd be content

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.