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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:43:13+00:00 2026-05-27T07:43:13+00:00

I am working on a WinForms application. There are four text boxes and one

  • 0

I am working on a WinForms application. There are four text boxes and one button in my form. I am using textBox1.SelectedText += "any string" on a button click so it writes to the first TextBox. If I add textBox1.SelectedText += "any string." then it writes both the textbox1 and textbox 2.

When I click textbox1 and press button then the sting only writes in the first textbox, and I click the second textbox and press the button then it write into second text box .Is there is any way to do this?

I’m using the following code.

private void button1_Click(object sender, EventArgs e)
{
    textBox1.SelectedText += "abc";
    textBox2.SelectedText += "abc";          
}

When I focus on the control, and when we press the button focus goes to the button. So how can we the focus on the one of the text boxes of my form after pressing the button?

  • 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-27T07:43:14+00:00Added an answer on May 27, 2026 at 7:43 am

    You can try this

        TextBox selTB = null;
    
        public Form1()
        {
            InitializeComponent();
            textBox1.Enter += tb_Enter;
            textBox2.Enter += tb_Enter;
            textBox3.Enter += tb_Enter;
            textBox4.Enter += tb_Enter;
        }
    
        ~Form1()
        {
            textBox1.Enter -= tb_Enter;
            textBox2.Enter -= tb_Enter;
            textBox3.Enter -= tb_Enter;
            textBox4.Enter -= tb_Enter;
        }
    
        private void tb_Enter(object sender, EventArgs e)
        {
            selTB = (TextBox)sender;
        }
    
    
        private void button1_Click(object sender, EventArgs e)
        {
            // Do what you need
            selTB.SelectedText += "abc";
    
            // Focus last selected textbox
            if (selTB != null) selTB.Focus();
        }
    

    The idea is that when you enter a textbox, you store it in selTB.
    So whan you click button, you know which one textbox was the last selected one.

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

Sidebar

Related Questions

I've got a WinForms application that I am working on. There is one small
I am working on a winforms application using LINQ to SQL - and am
My team working in a project using Winforms application(c#) & MSSQL 2005 as database.
I'm working on re-writing a WinForms application into Silverlight. One use case in the
I am working on a Winforms application and using C# as the development language.
I have a Winforms application which is working fine.. using a BackgroundWorkerThread to manage
I'm currently working on an client application developed using winforms on .Net 2.0. Are
I will be working on a Time Management application very soon using Winforms and
I have some nice, working edit-undo functionality in my winforms application. It works using
I'm working on a C# winforms application (VS.NET 2008, .NET 3.5 sp 1). 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.