Results 1 to 14 of 14

Thread: [RESOLVED] MDI Form and Control setfocus

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Resolved [RESOLVED] MDI Form and Control setfocus

    Hi,

    I'm working on MDI Form.
    In first MDI Form set focus set to text box control name txtPayment, and then i create New Form. When i back to old Form (other one MDI Form) how to set focus back to txtPayment?

    Thanks

  2. #2
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: MDI Form and Control setfocus

    txtPayment.SetFocus

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: MDI Form and Control setfocus

    Thanks randem,

    I forget to mention, beside txtPayment, other control on previous Form can have the focus to. How to determine what focus have control before this mdi form deactivate?

  4. #4
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: MDI Form and Control setfocus

    Screen.ActiveControl I believe

  5. #5
    Frenzied Member moinkhan's Avatar
    Join Date
    Jun 2000
    Location
    Karachi, Pakistan
    Posts
    2,011

    Re: MDI Form and Control setfocus

    Well i am sure you are talking about MDI Child form....

    and if you are unloading MDI Child form and going to another form say Form2.. and from Form2 you are again loading MDI Child form.. setting txtPayment TabIndex Property to 0 will help you...

    but if you are not unloading MDI Child form.. then write on unload of that Form1... mdichildform.txtpayment.setFocus... or if you are not unloading Form2 just write the same statement on the event where MDI child form is shown again..

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: MDI Form and Control setfocus

    Thanks randem, it work (activecontrol)
    But i have another question. Since i don't know what type of this control how to determine wheter this control have event/property such as setfocus?

    Thank's

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: MDI Form and Control setfocus

    Yes moinkhan, it's mdi child form.
    Sorry for my lack of explanation fro the problem i facing before.

    Follow randem i have this on my form:
    VB Code:
    1. Private Sub Form_Activate()
    2.     If varControlOnFocus Then
    3.         varControlOnFocus = False
    4.         If Not varObjectControlOnFocus.Visible Then varObjectControlOnFocus.Visible = True
    5.         varObjectControlOnFocus.SetFocus
    6.     End If
    7. End Sub
    8.  
    9. Private Sub Form_Deactivate()
    10.     Set varObjectControlOnFocus = ActiveControl
    11.     varControlOnFocus = True
    12. End Sub

    But i dont know how to determine wheter or not this control have setfocus event.


    Edited:
    How to check if that my variable "varObjectControlOnFocus" to hold variable type of "object" have value or not. Is that "IsEmpty" function will work?
    Last edited by barianto; Feb 6th, 2007 at 01:40 AM.

  8. #8
    Banned randem's Avatar
    Join Date
    Oct 2002
    Location
    Maui, Hawaii
    Posts
    11,385

    Re: MDI Form and Control setfocus

    You can easily test for that
    VB Code:
    1. On Error Resume Next
    2. Err.Clear
    3. control.SetFocus
    4. If Err.Number <> 0 then    
    5.    ' Control has no SetFocus Event
    6. End If
    7. On Error GoTo 0
    Last edited by randem; Feb 6th, 2007 at 02:14 AM.

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: MDI Form and Control setfocus

    Again, thanks randem. It Solved my problem.
    Any other suggestion from you that doesn't using Error trap? to wider my knowledge.

    Thanks

  10. #10
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: MDI Form and Control setfocus

    If you know what kind of controls have a SetFocus method, you can use this:
    VB Code:
    1. Select Case TypeName(varObjectControlOnFocus)
    2. Case "TextBox", "PictureBox"   'add other types here
    3.   varObjectControlOnFocus.SetFocus
    4. End Select

  11. #11
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: MDI Form and Control setfocus

    without error trapping or specifying which controls:
    VB Code:
    1. Private Sub Command1_Click()
    2.     Debug.Print CanSetFocus(Command1) ' True
    3.     Debug.Print CanSetFocus(Text1)    ' True
    4.     Debug.Print CanSetFocus(Line1)    ' False
    5. End Sub
    6.  
    7. ' Requires reference to TypeLib Information
    8. Private Function CanSetFocus(ByRef obj As Object) As Boolean
    9.     Dim objInterfaceInfo As TLI.InterfaceInfo
    10.     Dim objMemberInfo As TLI.MemberInfo
    11.    
    12.     Set objInterfaceInfo = TLI.TLIApplication.InterfaceInfoFromObject(obj)
    13.     For Each objMemberInfo In objInterfaceInfo.Members
    14.         If objMemberInfo.Name = "SetFocus" Then Exit For
    15.     Next objMemberInfo
    16.     CanSetFocus = Not (objMemberInfo Is Nothing)
    17.     Set objMemberInfo = Nothing: Set objInterfaceInfo = Nothing
    18. End Function
    (there might be a way of doing it about looping - but i can't be bothered to sit down and read all the documentation)

    and regarding your other question about checking if an object variable has a value use:
    VB Code:
    1. If Not [i]object[/i] is Nothing Then
    2.      '

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: MDI Form and Control setfocus

    si_the_geek:
    TypeName is what i looking for.

    bushmobile:
    This method definitely i will use on my application

    But when i try it it give "User-defined type not defined" on :
    VB Code:
    1. objInterfaceInfo As TLI.InterfaceInfo

    What should i do?

    Thanks guy
    Last edited by barianto; Feb 6th, 2007 at 08:02 PM.

  13. #13
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: MDI Form and Control setfocus

    Quote Originally Posted by me
    VB Code:
    1. ' Requires reference to TypeLib Information

  14. #14

    Thread Starter
    Addicted Member
    Join Date
    Nov 2005
    Posts
    145

    Re: MDI Form and Control setfocus

    Thanks,

    Found it , used to skip reading comment.
    Last edited by barianto; Feb 7th, 2007 at 05:53 AM.

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