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. webbrowser stealing focus

webbrowser stealing focus

Scheduled Pinned Locked Moved C#
5 Posts 2 Posters 0 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.
  • Y Offline
    Y Offline
    yeah1000
    wrote on last edited by
    #1

    Hello, i am using a webbrowser control on my form together with textboxes. What i need is that when i load the form the cursor will be in textbox, but instead the webbrowser "steals focus". I have tried using the Focus() property for the textbox in just about anywhere now but it still wont work. Also i have tried creating event handlers for webbrowser's different events (GotFocus, Validated etc) but nothing seems to work. The only thing that worked was the DocumentCompleted handler, which can make the cursor go to the textbox but not when the form loads, which is strange, since i have the browser go to a web page when the form loads (after InitializeComponent). TY

    OriginalGriffO 1 Reply Last reply
    0
    • Y yeah1000

      Hello, i am using a webbrowser control on my form together with textboxes. What i need is that when i load the form the cursor will be in textbox, but instead the webbrowser "steals focus". I have tried using the Focus() property for the textbox in just about anywhere now but it still wont work. Also i have tried creating event handlers for webbrowser's different events (GotFocus, Validated etc) but nothing seems to work. The only thing that worked was the DocumentCompleted handler, which can make the cursor go to the textbox but not when the form loads, which is strange, since i have the browser go to a web page when the form loads (after InitializeComponent). TY

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      What you need to do is set the Tab Order. This indicates which controls get the input focus in which order when you press tab to switch between them. The lowest tab order control gets the focus first on form load. Simple. Tab order is initialy assigned in order of control creation, so if you create your browser first, then create the textboxes, the browser gets the focus.

      No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      Y 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        What you need to do is set the Tab Order. This indicates which controls get the input focus in which order when you press tab to switch between them. The lowest tab order control gets the focus first on form load. Simple. Tab order is initialy assigned in order of control creation, so if you create your browser first, then create the textboxes, the browser gets the focus.

        No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

        Y Offline
        Y Offline
        yeah1000
        wrote on last edited by
        #3

        I forgot to mention it, but tab order has been set properly. The cursor still goes to google.com's search bar (google.com is the site being automatically loaded into webbrowser at startup).

        OriginalGriffO 1 Reply Last reply
        0
        • Y yeah1000

          I forgot to mention it, but tab order has been set properly. The cursor still goes to google.com's search bar (google.com is the site being automatically loaded into webbrowser at startup).

          OriginalGriffO Offline
          OriginalGriffO Offline
          OriginalGriff
          wrote on last edited by
          #4

          Just tried it, with a browser docked in a panel, and a textbox with button outside the panel. Set URL to "http:\\www.Google.co.uk" in design properties, TabIndex is Textbox = 0, button = 1, panel = 2.0 Works fine, Cursor in textbox on form load. How is this different from yours?

          No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

          "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
          "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

          Y 1 Reply Last reply
          0
          • OriginalGriffO OriginalGriff

            Just tried it, with a browser docked in a panel, and a textbox with button outside the panel. Set URL to "http:\\www.Google.co.uk" in design properties, TabIndex is Textbox = 0, button = 1, panel = 2.0 Works fine, Cursor in textbox on form load. How is this different from yours?

            No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones

            Y Offline
            Y Offline
            yeah1000
            wrote on last edited by
            #5

            Its not different. When i do the same thing, the cursor automatically goes to webbrowser :( I just discovered that the problem exists only with some pages (google, orkut, youtube, hotmail etc). When i use any of my local sites (.ee) then it works just fine. Why is that so? google and microsoft using some fancy scripts?

            modified on Wednesday, September 2, 2009 2:54 AM

            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