Results 1 to 7 of 7

Thread: help need to set focus on form1

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    India
    Posts
    158

    Question help need to set focus on form1

    hi guys,
    I have two forms in a vb6 project. Form1 has a timer, which loads form2 after some interval, and after loading form2 autometically closed after some second (and repeated till program running). My problem is that when form2 loads, it looses the focus from form1. I want to load form2 without disturbing or loosing focus from form1. Pleas help.

  2. #2
    VB For Fun Edgemeal's Avatar
    Join Date
    Sep 2006
    Location
    WindowFromPoint
    Posts
    4,255

    Re: help need to set focus on form1


  3. #3
    Fanatic Member
    Join Date
    Mar 2009
    Posts
    804

    Re: help need to set focus on form1

    Edgemeal's posted URL works fine. Here's a non-API approach:

    Code:
    Option Explicit
    Private Sub Form_Activate()
     SetFocus 'will error if called in Form_Load
    End Sub
    
    Private Sub Form_Load()
     Form2.Move Left + Width, Top
     Form2.Show
    End Sub
    
    Private Sub Form_Unload(Cancel As Integer)
     Unload Form2
    End Sub

  4. #4
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: help need to set focus on form1

    Just do after it loads Form2, say
    Form1.Show.
    That should work.
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Dec 2009
    Location
    India
    Posts
    158

    Re: help need to set focus on form1

    Quote Originally Posted by Gamemaster1494 View Post
    Just do after it loads Form2, say
    Form1.Show.
    That should work.
    That works, but it loads form1 in new window each time.

  6. #6
    Fanatic Member
    Join Date
    Oct 2009
    Location
    Missouri
    Posts
    770

    Re: help need to set focus on form1

    thats werid..... is it because you unloaded form 1?
    Rate my post if i helped you!


    Button Configuration Control For VB6 GetAsyncKeyState
    I'm the 7th best high school programmer in the nation!(according to SkillsUSA Nationals)(Used C#.Net)

  7. #7
    Hyperactive Member
    Join Date
    May 2009
    Posts
    274

    Re: help need to set focus on form1

    This works:

    In your sub that triggers form2 to load put;
    form2.show
    me.setfocus

    I just tried it with a command button and did exactly that, form2 loaded behind form1

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