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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T22:21:09+00:00 2026-05-20T22:21:09+00:00

I tried everything I know. The trouble must be that my textbox is in

  • 0

I tried everything I know. The trouble must be that my textbox is in a groupbox. I have a Mainform from which I move to another form. When I return to Mainform, I want a particular object to be focused. How is this done?
Here’s my code in my Mainform.

    private void button1_Click(object sender, EventArgs e)
    {
         Form1 frm = new Form1();
         frm.ShowDialog();
    }

now this is how i return back to my Mainform from Form1.

    private void button3_Click(object sender, EventArgs e)
    {
        this.DialogResult = DialogResult.OK;
    }

I have textBox1 in Mainform. How to set focus to textBox1 when quitting Form1 and entering Mainform. I tried textBox1.Focus(); and this.ActiveControl = this.textBox1; under Mainform Load, Show, Activated and Enter events. Still didn’t work. I tried creating a public method and call it under the exit button of Form1. Like this.

In Mainform,

    public void textBox1Focus()
    {
        textBox1.Focus();
    }

And then in Form1,

    private void button3_Click(object sender, EventArgs e)
    {
        this.DialogResult = DialogResult.OK;
        Mainform frm = new Mainform();
        frm.textBox1Focus();
    }

Which still didn’t work. My textBox1 is in a groupbox. Could that be the reason?

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-20T22:21:10+00:00Added an answer on May 20, 2026 at 10:21 pm

    I don’t understand how the code that you’ve shown even compiles. You’re calling textBox1Focus() from inside a method that’s defined in the Form1 class, which as best I can understand, doesn’t include a definition for textBox1Focus. That method is only defined in the Mainform class.

    And no, the text box being placed in a group box is not preventing it from getting the focus. There’s something else wrong with your code. It’s hard to tell; I feel like I’m looking at a sunset through Venetian blinds, rather than through a large picture window.

    Anyway, I suspect there’s a simpler solution. Just set the focus to the textbox control at the end of the button1_Click method. The ShowDialog method is a blocking call, which means execution won’t continue until after the user closes the second form. When that happens, execution will continue with the next line of code, which will set the focus to the textbox control.

    Try changing your code to the following:

    private void button1_Click(object sender, EventArgs e)
    {
         Form1 frm = new Form1();
         frm.ShowDialog();
         this.textBox1.Select();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a jQuery problem, and I've really tried everything I know (i am
I don't know why , i can't override back button: I tried everything I
I have tried everything in the book and EVERYTHING I could find on how
I have nearly tried everything but cannot figure out what is wrong. I have
I have tried everything, searched the net for two hours or even more and
I am having trouble preventing objects that my pointers are pointing from being freed.
I've already tried everything i know, but still can't get my checkboxlist checked values.
I'm have trouble getting a project at work to run. The problem is that
I tried everything to get this code working, and I hope someone will save
I tried everything to debug this one but I can't get to the bottom

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.