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. how to set focus a control in c#

how to set focus a control in c#

Scheduled Pinned Locked Moved C#
csharptutorialquestion
4 Posts 4 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.
  • S Offline
    S Offline
    stephen myint
    wrote on last edited by
    #1

    I used the flwing code to focus a control. But i got nothing. why? private void button1_Click(object sender, EventArgs e) { if (lst1.Items.Count > 0) { lst2.Items.Add(lst1.SelectedItem); lst1.Items.Remove(lst1.SelectedItem); } if (lst1.CanFocus) { lst1.Focus(); } } rgds, stephen myint

    T R H 3 Replies Last reply
    0
    • S stephen myint

      I used the flwing code to focus a control. But i got nothing. why? private void button1_Click(object sender, EventArgs e) { if (lst1.Items.Count > 0) { lst2.Items.Add(lst1.SelectedItem); lst1.Items.Remove(lst1.SelectedItem); } if (lst1.CanFocus) { lst1.Focus(); } } rgds, stephen myint

      T Offline
      T Offline
      Tom Larsen
      wrote on last edited by
      #2

      There is an design paradox here: To have this event, you need to click the buttom which forces the focus onto the button. If it was anywhere else, you wouldn't be able to click the button. You don't want things stealing focus while doing various operations (like clicking, drag-and-drop, etc) anyway. You should consider another UI design instead of trying to have focus jump around on the form while performing user input.

      1 Reply Last reply
      0
      • S stephen myint

        I used the flwing code to focus a control. But i got nothing. why? private void button1_Click(object sender, EventArgs e) { if (lst1.Items.Count > 0) { lst2.Items.Add(lst1.SelectedItem); lst1.Items.Remove(lst1.SelectedItem); } if (lst1.CanFocus) { lst1.Focus(); } } rgds, stephen myint

        R Offline
        R Offline
        Ravi Bhavnani
        wrote on last edited by
        #3

        Use the form's Select() method or ActiveControl property instead. /ravi My new year's resolution: 2048 x 1536 Home | Music | Articles | Freeware | Trips ravib(at)ravib(dot)com

        1 Reply Last reply
        0
        • S stephen myint

          I used the flwing code to focus a control. But i got nothing. why? private void button1_Click(object sender, EventArgs e) { if (lst1.Items.Count > 0) { lst2.Items.Add(lst1.SelectedItem); lst1.Items.Remove(lst1.SelectedItem); } if (lst1.CanFocus) { lst1.Focus(); } } rgds, stephen myint

          H Offline
          H Offline
          HimaBindu Vejella
          wrote on last edited by
          #4

          U can use Javascript client side scripting for setting focus "Aim to go where U have never been B4 and Strive to achieve it" http://groups.yahoo.com/subscribe/dotnetforfreshers http://himabinduvejella.blogspot.com

          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