Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. C# webbrowser control focus issues

C# webbrowser control focus issues

Scheduled Pinned Locked Moved C#
csharpquestion
9 Posts 2 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    Wheels012
    wrote on last edited by
    #1

    Good afternoon. I have a webrowser control on my main form and on the form load I set the URL for the control When the webpage loads, the focus stays on the webpage and I cannot seem to programatically move the focus to the combobox on the form. I even set the focus on the webbrowser control to False. Any suggestions? Thank you, WHEELS

    L 1 Reply Last reply
    0
    • W Wheels012

      Good afternoon. I have a webrowser control on my main form and on the form load I set the URL for the control When the webpage loads, the focus stays on the webpage and I cannot seem to programatically move the focus to the combobox on the form. I even set the focus on the webbrowser control to False. Any suggestions? Thank you, WHEELS

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Set the ComboBox on the top in the tab order. If that doesn't work, hook up a method to the DocumentCompleted event of the web browser control and set the focus to the ComboBox there.

      W 1 Reply Last reply
      0
      • L Lost User

        Set the ComboBox on the top in the tab order. If that doesn't work, hook up a method to the DocumentCompleted event of the web browser control and set the focus to the ComboBox there.

        W Offline
        W Offline
        Wheels012
        wrote on last edited by
        #3

        Hi Shameel. I did experiment with DocumentCompleted yesterday before I posted, but neither 'method' worked. Not sure hwy DocumentCompleted doesn't work though. However, I did get this to work:

        private void WebBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
        {
        this.cboSP_Site.Focus();
        }

        I appreciate your willingness to assist. Have a great day, WHEELS

        L 1 Reply Last reply
        0
        • W Wheels012

          Hi Shameel. I did experiment with DocumentCompleted yesterday before I posted, but neither 'method' worked. Not sure hwy DocumentCompleted doesn't work though. However, I did get this to work:

          private void WebBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e)
          {
          this.cboSP_Site.Focus();
          }

          I appreciate your willingness to assist. Have a great day, WHEELS

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          ProgressChanged would fire more than once (probably many times) during a single page load, so you end up setting focus many times :)

          W 1 Reply Last reply
          0
          • L Lost User

            ProgressChanged would fire more than once (probably many times) during a single page load, so you end up setting focus many times :)

            W Offline
            W Offline
            Wheels012
            wrote on last edited by
            #5

            I noticed that, but what can I do? WHEELS

            L 1 Reply Last reply
            0
            • W Wheels012

              I noticed that, but what can I do? WHEELS

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              DocumentCompleted SHOULD fire when document is completed loaded. Try to find out why it is not working.

              W 1 Reply Last reply
              0
              • L Lost User

                DocumentCompleted SHOULD fire when document is completed loaded. Try to find out why it is not working.

                W Offline
                W Offline
                Wheels012
                wrote on last edited by
                #7

                Thank you Shameel. That will be my primary focus today. However, one thing I noticed, is that some web pages hijack the focus (e.g. Google), 'holding' it in the search box. My feeling is that when this occurs, the DocumentCompleted will not fire. WHEELS

                L 1 Reply Last reply
                0
                • W Wheels012

                  Thank you Shameel. That will be my primary focus today. However, one thing I noticed, is that some web pages hijack the focus (e.g. Google), 'holding' it in the search box. My feeling is that when this occurs, the DocumentCompleted will not fire. WHEELS

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  I just created a small app to see myself what the problem is, and as you said, setting focus to the other control in DocumentCompleted event doesn't work. The reason I found is that DocumentCompleted is fired when the browser completes loading the html content of the page and google runs a javascript in its onload event to set focus to the search box. This happens after the DocumentCompleted event executes and therefore focus goes back to the control. But ProgressChanged event works, and I found a workaround to do away with setting focus multiple times. Use this code:

                  private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e) {
                  if (e.CurrentProgress == e.MaximumProgress) {
                  textBox1.Focus();
                  }
                  }

                  W 1 Reply Last reply
                  0
                  • L Lost User

                    I just created a small app to see myself what the problem is, and as you said, setting focus to the other control in DocumentCompleted event doesn't work. The reason I found is that DocumentCompleted is fired when the browser completes loading the html content of the page and google runs a javascript in its onload event to set focus to the search box. This happens after the DocumentCompleted event executes and therefore focus goes back to the control. But ProgressChanged event works, and I found a workaround to do away with setting focus multiple times. Use this code:

                    private void webBrowser1_ProgressChanged(object sender, WebBrowserProgressChangedEventArgs e) {
                    if (e.CurrentProgress == e.MaximumProgress) {
                    textBox1.Focus();
                    }
                    }

                    W Offline
                    W Offline
                    Wheels012
                    wrote on last edited by
                    #9

                    Works great. Thank you. WHEELS

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups