Results 1 to 7 of 7

Thread: How do I force a form to get the focus?

  1. #1

    Thread Starter
    Addicted Member Daniel_Christie's Avatar
    Join Date
    Jan 2000
    Location
    USA
    Posts
    245
    I use an GetAsyncKeyState api to catch a hotkey press and set my form to visible. I have a specific text box I wanted to get the focus the second the form is visible so my users can begin typing immediately. When I coded my timer to catch the hotkey press I also coded it to give txtSend.Focus but all that happens is that my form appears and the title barflashes a few times but neither my form nor the txtSend gets a focus. How do I allow my form once it is visible, to give my txtSend the focus so my users can begin typing into the txtSend box immediately after the form is visible, without having to manually click the form with a mouse?

    I appreciate any time or effort,
    Daniel Christie

  2. #2
    Hyperactive Member D12Bit's Avatar
    Join Date
    Oct 2000
    Location
    Guatemala
    Posts
    373

    Wink Have you tried this

    Hello,

    Have you tried to set the focus of the text this way

    Code:
    frmName.Visible = True
    frmName.txtSend.SetFocus
    This way i can be able to start typing in the textbox without
    any trouble, give it a try...

    Saludos...

    "Who Dares Wins" - "Quien se Arriesga Gana"
    Mail me at:

  3. #3

    Thread Starter
    Addicted Member Daniel_Christie's Avatar
    Join Date
    Jan 2000
    Location
    USA
    Posts
    245
    hmmm... "nope go fish".

    It didn't work...

    Here is the form load:

    Private Sub Form_Load()
    Dim address As String

    'Begin security coding
    Call RemoveProgramFromList
    frmBrowser.Visible = False

    'Start the watch for HideME HotKey presses
    tmrVisibleF.Enabled = True

    'Begin Navigate
    Open "file.dat" For Input As #1
    Input #1, address
    Close
    brwWebBrowser.Navigate address

    'Get the current size of the HTML Chat file
    Open address For Binary As #1
    lblLOF.Caption = LOF(1)
    Close
    End Sub

    HERE IS THE TMR CODE TO MAKE FORM VISIBLE:

    Private Sub tmrVisible_Timer()
    'Check whether the ((Shift) + (Numeric pad's +)) keys have been pressed.
    'If they have been pressed then frmBrowser Shows.
    If (GetAsyncKeyState(&H10)) And (GetAsyncKeyState(&H6B)) Then
    frmBrowser.Visible = True
    tmrVisible.Enabled = False
    tmrVisibleF.Enabled = True
    txtSend.SetFocus
    End If
    End Sub


    Why is it that once the form is visible=false on form load and then visible=true for the first time, the title bar always flashes and the txtSend box does not get the focus?

    Every other time it is Visible=False then back to visible=True the txtSend gets the focus, it's justfirst time from the load thatit never gets the focus, know why?

    I appreciate your time and efforts,
    Daniel Christie

  4. #4
    Guest
    Try using hide and show rather than visible.

    Code:
    frmBrowser.Hide
    '''''''''
    frmBrowser.Show 
    txtSend.SetFocus

  5. #5

    Thread Starter
    Addicted Member Daniel_Christie's Avatar
    Join Date
    Jan 2000
    Location
    USA
    Posts
    245

    It has to be Visible insteade of hide for security reasons

    Nope, unfortunately this has to be visible instead of hide for security reasons.

    Thanks for the good suggestions though.
    Daniel Christie

  6. #6
    Guest
    Try using the SetForegroundWindow api function.

    Code:
    Public Declare Function SetForegroundWindow Lib "user32" _
    (ByVal hwnd As Long) As Long
    
    Usage
    
    SetForegroundWindow Text1.hwnd


  7. #7
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Have you tried disabling the timer once it has completed it's task.

    tmrVisible_Timer.enabled = false



    [Edited by HeSaidJoe on 10-31-2000 at 08:53 AM]
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

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