|
-
May 31st, 2007, 04:50 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] SetFocus on form created in RunTime
Hi 
My app creates several forms in runtime and I want to set focus on it.
How can I make this?
Thank you
-
May 31st, 2007, 05:06 AM
#2
Re: SetFocus on form created in RunTime
Only one form can have focus at a time and loading the form after it is created should establish focus.
-
May 31st, 2007, 05:19 AM
#3
Thread Starter
Hyperactive Member
Re: SetFocus on form created in RunTime
Yes, I understand that, but my real problem is a little diferent.Let me explain:
I've got a TreeView with multiple nodes, each node creates a form in runtime.
Meanwhile, the user opens another app windows, and then, clicks again in the TreeView.
I'm validating if the forms created in runtime are open or close (using a array , type boolean).
So, when the user clicks for the 2nd, 3rd, ... time in the treeview, the window should get focus,if it's open already. If not, then the app will create the form in runtime and, off-course, the new window will get focus.
-
May 31st, 2007, 07:26 AM
#4
Re: SetFocus on form created in RunTime
What is your code for your validation array?
-
May 31st, 2007, 07:54 AM
#5
Thread Starter
Hyperactive Member
Re: SetFocus on form created in RunTime
The var (List) is an array.
This var is based uppon the node.Key of TreeView.
Code:
List= CInt(Replace(Node.Key, "n", ""))
When I create the form:
Code:
FormInUse(List) = True
When I close the form:
Code:
FormInUse(List) = False
Could I use API's?
-
May 31st, 2007, 07:58 AM
#6
Re: SetFocus on form created in RunTime
Doesn't .Showing the form set focus to it even if it's already been shown?
-
May 31st, 2007, 08:01 AM
#7
Thread Starter
Hyperactive Member
Re: SetFocus on form created in RunTime
No, dude, because when I do "formList.show" it only show my basic form, not the runtime form created.
-
May 31st, 2007, 09:15 AM
#8
Re: SetFocus on form created in RunTime
I'm not understanding your problem then, because testing it out both .Show and .SetFocus seem to do what you're looking for.
Create a new project with two forms. (Form1 & Form2) Add two command buttons to Form1. (Command1 & Command2) Then copy this code to Form1's module. Then run it.
Clicking Command1 will create new forms. Clicking Form2 will cause the first created form to get the focus using the .Show method. .SetFocus works as well.
Code:
Option Explicit
Private Sub Command1_Click()
Static lngNumber As Long
Dim frm As Form
lngNumber = lngNumber + 1
Set frm = New Form2
frm.Caption = lngNumber
frm.Show
Set frm = Nothing
End Sub
Private Sub Command2_Click()
Dim frm As Form
For Each frm In Forms
If frm.Caption = "1" Then frm.Show
Next
Set frm = Nothing
End Sub
-
May 31st, 2007, 10:34 AM
#9
Thread Starter
Hyperactive Member
Re: SetFocus on form created in RunTime
Ok, that should work, but not in my specific case. Some forms created in runtime must have the same caption.
Forms must have an unique identifier internally, right?
If so, how can I determine it? Is there any API function to do it?
Thank you
-
May 31st, 2007, 02:53 PM
#10
Re: SetFocus on form created in RunTime
Using API and determining the form's internal ID number is way overkill. Just make up your own unique identifier for the forms, (like, say, the treeview node's .Key property) and stuff that into the forms' .Tag property.
Code:
Option Explicit
Private Sub Command1_Click()
Dim frm As Form
If Not Treeview1.SelectedItem Is Nothing Then
Set frm = New Form2
frm.Tag = Treeview1.SelectedItem.Key
frm.Show
Set frm = Nothing
End If
End Sub
Private Sub Command2_Click()
Dim frm As Form
For Each frm In Forms
If frm.Tag = [some value] Then frm.Show
Next
Set frm = Nothing
End Sub
Last edited by Ellis Dee; May 31st, 2007 at 02:57 PM.
-
Jun 1st, 2007, 03:45 AM
#11
Thread Starter
Hyperactive Member
Re: SetFocus on form created in RunTime
Thanks for the suggestion. I've use the tag property to track my forms.
Here it goes the code:
Code:
Private Sub Navigator_NodeClick(ByVal Node As MSComctlLib.Node)
Dim NodeClick As Integer
Dim formul As Form
On Error Resume Next
If FormInUse(NodeClick) Then
For Each formul In Forms
If formul.Tag = NodeClick Then formul.SetFocus
Next
Exit Sub
Else
Set NewForm = New Lista
NewForm.Show
NewForm.Tag = NodeClick
NewForm.load_Grid (NodeClick)
Set NewForm = Nothing
End If
End Sub
Thank you all
-
Jun 1st, 2007, 04:46 AM
#12
Re: [RESOLVED] SetFocus on form created in RunTime
That can't possibly work, or it is incomplete. NodeClick is always zero; you never set it to anything.
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
|