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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:53:51+00:00 2026-06-17T05:53:51+00:00

I’m writing in C#. I have a process that lunches a third party application

  • 0

I’m writing in C#.

I have a process that lunches a third party application embedded within my program.
I also have a RichTextBox in which I write text and then it shown in the embedded application real time. Everything works but I need to move the mouse, for the application will get focus and then refresh and show me the changes.

This is the process:

private void button2_Click(object sender, EventArgs e)
{
    System.IO.File.WriteAllText(@"ForParsing.txt", textBox1.Text);

    pdf.StartInfo.FileName = @"yap.exe";
    pdf.StartInfo.Arguments = "ForParsing.dvi";
    pdf.Start();
    pdf.WaitForInputIdle(-1);
    SetParent(pdf.MainWindowHandle, this.splitContainer2.Panel1.Handle);
    SetWindowPos(pdf.MainWindowHandle, HWND_TOP,
        this.splitContainer2.Panel1.ClientRectangle.Left,
        this.splitContainer2.Panel1.ClientRectangle.Top,
        this.splitContainer2.Panel1.ClientRectangle.Width,
        this.splitContainer2.Panel1.ClientRectangle.Height,
        SWP_NOACTIVATE | SWP_SHOWWINDOW);
} 

I have a key press handler below for the TextBox.
When key is pressed, I Focus on a third party application that is embedded in my program.

private void richTextBox1_TextChanged(object sender, EventArgs e)
{
            System.IO.File.WriteAllText(@"ForParsing.txt", textBox1.Text);
            //Focus on third party application
            SetForegroundWindow(pdf.MainWindowHandle);
}

So far so good.
Now the problem: I want the focus instantly returned to the same place the courser was in the TextBox. I want to be able to keep on writing in the TextBox like nothing happened except the real time refreshing of the embedded application.

In simple words, I need the third party application to refresh (gain focus) instantly and me be able to type without interference, at the current position I stopped, in the TextBox.

Is it possible to so? Is there a better, more simple solution for this? would happily listen to any advice.

As I’m not allowed to answer my own questions, I will write it here:

I’ve found a solution tinkering with people’s problems

Here is what I’ve done:

private void richTextBox1_TextChanged(object sender, EventArgs e)
{
System.IO.File.WriteAllText(@”ForParsing.txt”, textBox1.Text);

        //Focus on third party application
        SetForegroundWindow(pdf.MainWindowHandle);

        //Restore focus
        pdf.WaitForInputIdle();
        SetForegroundWindow(this.Handle);
        this.Focus();

}

Thanks for the help everyone

  • 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-06-17T05:53:53+00:00Added an answer on June 17, 2026 at 5:53 am

    When you need it to focus back up:

    if (!handle.Equals(IntPtr.Zero))
    {
        if (NativeMethods.IsIconic(WindowHandle))
            NativeMethods.ShowWindow(WindowHandle, 0x9); // Restore
    
        NativeMethods.SetForegroundWindow(handle);
    }
    

    Where:

    [DllImport("User32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    internal static extern Boolean IsIconic([In] IntPtr windowHandle);
    
    [DllImport("User32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    internal static extern Boolean SetForegroundWindow([In] IntPtr windowHandle);
    
    [DllImport("User32.dll", CharSet = CharSet.Unicode, ExactSpelling = true, SetLastError = true)]
    [return: MarshalAs(UnmanagedType.Bool)]
    internal static extern Boolean ShowWindow([In] IntPtr windowHandle, [In] Int32 command);
    

    Normally, when you focus back, the tabindex is always on the same position you left it to. So it shoundn’t be a problem…

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

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have an autohotkey script which looks up a word in a bilingual dictionary
I have an array which has BIG numbers and small numbers in it. I
I have a text area in my form which accepts all possible characters from
I have thousands of HTML files to process using Groovy/Java and I need to
I am writing an app for my school newspaper, which is run completely online
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.