Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I know so much but this doesn't work other than the first time the form is shown...

What I have tried:

switch (e.KeyCode)
            {
                case Keys.F1:
                    e.Handled = true;

                    formMain.webBrowserMain.Navigate(@"translate.google.com");

                    formMain.TopMost = true;

                    formMain.WindowState = FormWindowState.Minimized;
                    formMain.Show();
                    formMain.WindowState = FormWindowState.Normal;
                    formMain.BringToFront();

                    formMain.panelMain.Enabled = false;
                    formMain.Focus();
                    formMain.panelMain.Enabled = true;
               
                    
                    formMain.webBrowserMain.Focus();
                    
                    break;
            }



and this:


private void webBrowserMain_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            
            if (webBrowserMain.ReadyState == WebBrowserReadyState.Complete)
            {
                int numOfTries = 0;
            repeat:
                if (numOfTries < 10)
                {
                    try
                    {
                        webBrowserMain.Document.Window.ScrollTo(0, 0);
                        webBrowserMain.Document.GetElementById("source").Focus();
                    }
                    catch
                    {//if the document hasn't loaded yet
                        numOfTries++;
                        System.Threading.Thread.Sleep(40);
                        goto repeat;
                    }
                }
            }
        }
Posted
Updated 26-Jan-17 23:30pm
Comments
[no name] 26-Jan-17 13:14pm    
"this doesn't work other than the first time the form is shown", that's precisely why you run your code in the debugger so you can find out why. Then you could give us relevant information instead of saying "doesn't work".
john1990_1 26-Jan-17 13:31pm    
i get script errors as if the code runs before the document is totally complete.
[no name] 26-Jan-17 15:59pm    
Okay so wait until the document completes loading. Not sure why you think we can see your screen to see the errors you see. We can't run your code for you.
john1990_1 27-Jan-17 3:55am    
i use 2 ways for making sure the document is completed as u see above (DocumentCompleted and ReadyState), and still the code runs without the document being complete, will u do the program for me please? (check other comment)
john1990_1 26-Jan-17 13:50pm    
Will someone please make this app that shows Google Translate window when one presses F1 and focuses on the typing textbox so one translates because Babylon translation software is having technical issues of Windows lagging and i can't find an alternative.... the program would be very useful and famous... make an article.. Okay?

1 solution

I solved it by making
formMain.Activate();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900