|
-
Feb 6th, 2007, 12:57 AM
#1
Thread Starter
Addicted Member
[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
-
Feb 6th, 2007, 01:09 AM
#2
Re: MDI Form and Control setfocus
-
Feb 6th, 2007, 01:12 AM
#3
Thread Starter
Addicted Member
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?
-
Feb 6th, 2007, 01:16 AM
#4
Re: MDI Form and Control setfocus
Screen.ActiveControl I believe
-
Feb 6th, 2007, 01:21 AM
#5
Frenzied Member
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..
-
Feb 6th, 2007, 01:25 AM
#6
Thread Starter
Addicted Member
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
-
Feb 6th, 2007, 01:30 AM
#7
Thread Starter
Addicted Member
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:
Private Sub Form_Activate()
If varControlOnFocus Then
varControlOnFocus = False
If Not varObjectControlOnFocus.Visible Then varObjectControlOnFocus.Visible = True
varObjectControlOnFocus.SetFocus
End If
End Sub
Private Sub Form_Deactivate()
Set varObjectControlOnFocus = ActiveControl
varControlOnFocus = True
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.
-
Feb 6th, 2007, 02:02 AM
#8
Re: MDI Form and Control setfocus
You can easily test for that
VB Code:
On Error Resume Next
Err.Clear
control.SetFocus
If Err.Number <> 0 then
' Control has no SetFocus Event
End If
On Error GoTo 0
Last edited by randem; Feb 6th, 2007 at 02:14 AM.
-
Feb 6th, 2007, 02:08 AM
#9
Thread Starter
Addicted Member
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
-
Feb 6th, 2007, 07:56 AM
#10
Re: MDI Form and Control setfocus
If you know what kind of controls have a SetFocus method, you can use this:
VB Code:
Select Case TypeName(varObjectControlOnFocus)
Case "TextBox", "PictureBox" 'add other types here
varObjectControlOnFocus.SetFocus
End Select
-
Feb 6th, 2007, 01:11 PM
#11
Re: MDI Form and Control setfocus
without error trapping or specifying which controls:
VB Code:
Private Sub Command1_Click()
Debug.Print CanSetFocus(Command1) ' True
Debug.Print CanSetFocus(Text1) ' True
Debug.Print CanSetFocus(Line1) ' False
End Sub
' Requires reference to TypeLib Information
Private Function CanSetFocus(ByRef obj As Object) As Boolean
Dim objInterfaceInfo As TLI.InterfaceInfo
Dim objMemberInfo As TLI.MemberInfo
Set objInterfaceInfo = TLI.TLIApplication.InterfaceInfoFromObject(obj)
For Each objMemberInfo In objInterfaceInfo.Members
If objMemberInfo.Name = "SetFocus" Then Exit For
Next objMemberInfo
CanSetFocus = Not (objMemberInfo Is Nothing)
Set objMemberInfo = Nothing: Set objInterfaceInfo = Nothing
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:
If Not [i]object[/i] is Nothing Then
'
-
Feb 6th, 2007, 07:52 PM
#12
Thread Starter
Addicted Member
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:
objInterfaceInfo As TLI.InterfaceInfo
What should i do?
Thanks guy
Last edited by barianto; Feb 6th, 2007 at 08:02 PM.
-
Feb 7th, 2007, 03:22 AM
#13
Re: MDI Form and Control setfocus
 Originally Posted by me
VB Code:
' Requires reference to TypeLib Information
-
Feb 7th, 2007, 05:14 AM
#14
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|