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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:29:16+00:00 2026-05-24T05:29:16+00:00

I have several controls in a panel, and I want to make a button

  • 0

I have several controls in a panel, and I want to make a button that removes the one that has focus at the time that the button get clicked. I tried iterating through the controls in the panel to check if any of them has focus, but it always evaluates to false. I suspect that this is because the button gets focus as soon as it is clicked. If this is what is happening, can someone please tell me how I can keep track of the last control in the panel to have focus. Maybe an event every time focus changes? And if this is not what is happening, can someone please tell me what they think is happening. Thank you in advance.

  • 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-24T05:29:17+00:00Added an answer on May 24, 2026 at 5:29 am

    You are right — as soon as the button is pressed, all the other controls will lose focus.

    You can work around this by listening for the GotFocus event to remember which was the most recently selected one. For example:

    public partial class YourForm
    {
        private Control _LastFocusedControl;
    
        public YourForm()
        {
            InitializeComponent();
    
            var controlsToWatchForFocusChange = ...;   // Some IEnumerable<Control>, e.g. `new[] { txtTextBox1, txtTextBox2 }`
            foreach (var control in controlsToWatchForFocusChange) {
                control.GotFocus += (sender, e) => _LastFocusedControl = (Control)sender;
            }
        }
    }
    

    Then when your button is pressed, the last control to have focus will be accessible via _LastFocusedControl.

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

Sidebar

Related Questions

I have inherited a working VB.NET 2.0 web app that has several User Controls
I have a Silverlight user control that has several canvas controls within a Stack
I have several server controls that implement the IValidator interface. As such, they have
I have several questions concerning the controls like a button, if You could answer
I have a Windows form with a panel with several controls on it. The
In my app I have a xib that has several viewcontrollers and xibs (with
I have a custom control that has an update panel in it. Within the
I have a large HTML file (In ASP.NET) that has several smaller ... tags
I have several controls on a page that contain the word DATE in the
I have a page and in that page i have several user controls, so

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.