Results 1 to 11 of 11

Thread: firsttime focus

  1. #1

    Thread Starter
    Lively Member afterMoon's Avatar
    Join Date
    Oct 2002
    Location
    cochin
    Posts
    117

    firsttime focus

    how can I give focus to a textbox when the application starts?
    where should i put the code 'textbox1.focus()?
    thanks in advance
    when in doubt, win the trick

  2. #2
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    couldnt you just set the tabindex of it to 0?
    you could also put textbox.focus () in form_load, couldnt you?
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  3. #3

    Thread Starter
    Lively Member afterMoon's Avatar
    Join Date
    Oct 2002
    Location
    cochin
    Posts
    117
    hi Mr.Polite

    I placed some textboxes in a tabControl and made the tabindex of a textbox to 0.
    but it didn't work. why?
    it's working otherwise
    when in doubt, win the trick

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    Actually instead of SetFocus its now called Select() but setting the TabIndex to 0 should work.

  5. #5

    Thread Starter
    Lively Member afterMoon's Avatar
    Join Date
    Oct 2002
    Location
    cochin
    Posts
    117
    but setting tabindex to 0 for a textbox which is placed in a tabcontrol is not getting focus. do u know why?

    by the way
    Instead of setfocus it's object.focus() in vb.net right?
    i think select method is used to make a selection of the contents of a textbox. right?
    when in doubt, win the trick

  6. #6

    Thread Starter
    Lively Member afterMoon's Avatar
    Join Date
    Oct 2002
    Location
    cochin
    Posts
    117
    but setting tabindex to 0 for a textbox which is placed in a tabcontrol is not getting focus. do u know why?

    by the way
    Instead of setfocus it's object.focus() in vb.net right?
    i think select method is used to select a range of text in textbox. right?
    when in doubt, win the trick

  7. #7
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    errrrrrrrrm, here's a really dumb way to do it. Since no one else can think of the correct way :
    VB Code:
    1. Private Sub TabControl1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TabControl1.SelectedIndexChanged
    2.         Dim firstCtrl, ctrl As Control
    3.  
    4.         For Each ctrl In TabControl1.SelectedTab.Controls
    5.             If firstCtrl Is Nothing  OrElse (ctrl.TabIndex < firstCtrl.TabIndex) Then
    6.                 firstCtrl = ctrl
    7.             End If
    8.         Next
    9.  
    10.         If Not firstCtrl Is Nothing Then firstCtrl.Focus()
    11.     End Sub
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  8. #8

    Thread Starter
    Lively Member afterMoon's Avatar
    Join Date
    Oct 2002
    Location
    cochin
    Posts
    117
    ha ha! thank you very much Mr.Polite. But ....
    should we really write that much code for that?
    any way thanks
    when in doubt, win the trick

  9. #9
    Frenzied Member DevGrp's Avatar
    Join Date
    Nov 2001
    Location
    Charlotte, NC
    Posts
    1,256
    I dont think you need all that code. Just put
    VB Code:
    1. textBox1.Focus()
    in the form load event.
    Dont gain the world and lose your soul

  10. #10
    l33t! MrPolite's Avatar
    Join Date
    Sep 2001
    Posts
    4,428
    Originally posted by DevGrp
    I dont think you need all that code. Just put
    VB Code:
    1. textBox1.Focus()
    in the form load event.
    well, he wants the control to have the focus as the tabs are selected. I wrote the code like that so it would select the control with the lowest tabindex, everytime you select a different tab. This works even if you dont know the name of the control with the lowest tabindex in each tab
    rate my posts if they help ya!
    Extract thumbnail without reading the whole image file: (C# - VB)
    Apply texture to bitmaps: (C# - VB)
    Extended console library: (VB)
    Save JPEG with a certain quality (image compression): (C# - VB )
    VB.NET to C# conversion tips!!

  11. #11
    New Member
    Join Date
    May 2004
    Posts
    5

    Setting focus on Textbox at program start

    This is how to set focus

    Private Sub Form_activate()
    text1.setfocus
    End Sub


    text1 refering to which textbox you wish to focus on.

    Do this in order of forms that appear and on those forms which
    boxes you wish to start the sequence of tabs with.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width