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
  1. Home
  2. General Programming
  3. C#
  4. Can't focus TextBox on TabPage

Can't focus TextBox on TabPage

Scheduled Pinned Locked Moved C#
helpquestion
6 Posts 3 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.
  • T Offline
    T Offline
    Tavbi
    wrote on last edited by
    #1

    Hi, I have small but very annoying problem. My form contain tabcontrol with more tabpages. When I click on separate tabpage I want set focus to first textbox on selected tabpage. Second option for select tabpage is pressing keys from F1 to F8. I tried set textbox as ActiveControl on this form and I tried set focus but it didn't work. I noticed in some cases when I press tab after selecting tabpage focus go to textbox. So I use SendKeys.Send("{Tab}"), but dont't work when I focus tabpage with pressing key. I spent a lot of times to solve problem btu no success. Has anybody solution for my problem? Thanks in advance, Jure

    L O 2 Replies Last reply
    0
    • T Tavbi

      Hi, I have small but very annoying problem. My form contain tabcontrol with more tabpages. When I click on separate tabpage I want set focus to first textbox on selected tabpage. Second option for select tabpage is pressing keys from F1 to F8. I tried set textbox as ActiveControl on this form and I tried set focus but it didn't work. I noticed in some cases when I press tab after selecting tabpage focus go to textbox. So I use SendKeys.Send("{Tab}"), but dont't work when I focus tabpage with pressing key. I spent a lot of times to solve problem btu no success. Has anybody solution for my problem? Thanks in advance, Jure

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, my first attempt would be to remove all fancy code (SendKeys, ActiveControl, ...) and to set TabStop=true and TabIndex=0 for the control you want to get focus on a tab page. If that is not sufficient, I would use the TabControl.SelectedIndexChanged event Hope this helps. :)

      Luc Pattyn [My Articles] [Forum Guidelines]

      T 2 Replies Last reply
      0
      • T Tavbi

        Hi, I have small but very annoying problem. My form contain tabcontrol with more tabpages. When I click on separate tabpage I want set focus to first textbox on selected tabpage. Second option for select tabpage is pressing keys from F1 to F8. I tried set textbox as ActiveControl on this form and I tried set focus but it didn't work. I noticed in some cases when I press tab after selecting tabpage focus go to textbox. So I use SendKeys.Send("{Tab}"), but dont't work when I focus tabpage with pressing key. I spent a lot of times to solve problem btu no success. Has anybody solution for my problem? Thanks in advance, Jure

        O Offline
        O Offline
        originSH
        wrote on last edited by
        #3

        if (this.tabControl1.SelectedTab == this.tabPage1) this.textBox1.Focus(); else if (this.tabControl1.SelectedTab == this.tabPage2) this.textBox3.Focus(); That should do it.

        T 1 Reply Last reply
        0
        • O originSH

          if (this.tabControl1.SelectedTab == this.tabPage1) this.textBox1.Focus(); else if (this.tabControl1.SelectedTab == this.tabPage2) this.textBox3.Focus(); That should do it.

          T Offline
          T Offline
          Tavbi
          wrote on last edited by
          #4

          Hi, I tried this again, but doesn't work. Focus stay in textbox on previous tabpage. Thanks all the same.

          1 Reply Last reply
          0
          • L Luc Pattyn

            Hi, my first attempt would be to remove all fancy code (SendKeys, ActiveControl, ...) and to set TabStop=true and TabIndex=0 for the control you want to get focus on a tab page. If that is not sufficient, I would use the TabControl.SelectedIndexChanged event Hope this helps. :)

            Luc Pattyn [My Articles] [Forum Guidelines]

            T Offline
            T Offline
            Tavbi
            wrote on last edited by
            #5

            Hi, the use of Sendkeys or ActiveControl was just experiment from despair. I already have set TabStop=true and TabIndex=0. When I run my code with debugger I can see than code where I set focus is called just before show new tabpage. But focus stay in textbox on previous tabpage. Thanks anyway

            1 Reply Last reply
            0
            • L Luc Pattyn

              Hi, my first attempt would be to remove all fancy code (SendKeys, ActiveControl, ...) and to set TabStop=true and TabIndex=0 for the control you want to get focus on a tab page. If that is not sufficient, I would use the TabControl.SelectedIndexChanged event Hope this helps. :)

              Luc Pattyn [My Articles] [Forum Guidelines]

              T Offline
              T Offline
              Tavbi
              wrote on last edited by
              #6

              Hi, again! My problem is solved thanks to you. I move code from event TabControl.Selected to TabControl.SelectedIndexChanged as you have writen and now all work fine. Thank you very much!

              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