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

The Archive Base Latest Questions

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

Whenever a Form is opened, the system automatically focuses one of the controls for

  • 0

Whenever a Form is opened, the system automatically focuses one of the controls for you. As far as I can tell, the control that gets focus is the first enabled control in the tab order, as per Windows standard behavior.

The question is how to change this at run time without having to dynamically reshuffle the tab order. For instance, some forms might want to vary the initially-focused control based on program logic, to put focus in the most appropriate control. If you just focus some other control inside your OnLoad handler, the default logic executes anyway and re-focuses the default control.

If you’re writing in C/C++ and using a raw window procedure or MFC, you can return 0 (FALSE) from your WM_INITDIALOG handler, and the default focusing logic gets skipped. However, I can’t find any way to do this in Windows Forms. The best I’ve come up with is to use BeginInvoke to set the focus after the OnLoad finishes, like so:

protected override void OnLoad( System.EventArgs e )
{
    base.OnLoad( e );
    // ... code ...
    BeginInvoke( new MethodInvoker( () => this.someControl.Focus() ) );
}

There must be some proper way to do this – what is it?

  • 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-11T21:44:04+00:00Added an answer on May 11, 2026 at 9:44 pm

    After digging around through Reflector, I found what appears to be the “correct” way to do this: using ContainerControl.ActiveControl. This can be done from OnLoad (or elsewhere; see the docs for limitations) and directly tells the framework which control you want to be focused.

    Example usage:

    protected override void OnLoad( System.EventArgs e )
    {
        base.OnLoad( e );
        // ... code ...
        this.ActiveControl = this.someControl;
    }
    

    This seems like the cleanest and simplest solution so far.

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

Sidebar

Related Questions

I have code that gets called whenever the form is submitted, this then validates
Is there ASP button that won't submit post form data. Whenever I click an
I have a chart that I would like to update whenever a form on
Is there a jQuery plugin out there that can serialize a form, and then
whenever i send a form hidden field to paypal with an email as a
My form contains a ComboBox and a TextField. Whenever the user selects something in
The Scene: A (smallish) Form hosting a UserControl. The Plot: Whenever UserControl raises a
I wrote a simple contact form for a client in Django. However, whenever it
I have the formwizard plugin integrated with an 8-step form; The problem is, whenever
Whenever I learn a new language/framework, I always make a content management system... I'm

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.