|
-
Feb 9th, 2006, 04:51 PM
#1
Thread Starter
New Member
SSTab as a Container
I wrote a function that loops through all the controls of a form, so that I could set some of the properties of all those that belong to a certain container.
This is a small version of that function:
VB Code:
Public Sub setControls(ByVal formulary As Form, ByVal prefix As String, text As String)
prefix = UCase(prefix)
Dim control As control
For Each control In formulary.Controls
If InStr(1, UCase(control.Container.Name), prefix) > 0 Then
If TypeName(control) = "TextBox" Then
control.text = text
End If
End If
Next
End Sub
When I call the function
VB Code:
Call setControls(Me, "Frame", "Hi")
it sets every textbox text to "Hi" in all containers whose name starts on "Frame". BUT (cause there is a but) in the case of a SSTab control it's different, because I can't change the properties of the members of just ONE specific tab since the container is the SSTab control and not something like SSTab(1).
The thing is: is there any way to know is a control belongs to a specific tab in a SSTab control?
-
Feb 9th, 2006, 04:55 PM
#2
-
Feb 9th, 2006, 05:05 PM
#3
Thread Starter
New Member
Re: SSTab as a Container
Thanks. But I have so many controls in the tabs that going one by one is a little bit boring, besides it makes less automatic, since I have to remember doing it every time I make a SSTab control.
-
Feb 9th, 2006, 05:08 PM
#4
Re: SSTab as a Container
To find out which Tab a control is on you would need to loop through the Tabs, setting each Tab as the current Tab. When a Tab becomes current, the Left property of all controls is adjusted - ie the controls are moved into view.
You can then check the Left property of the Control. If it is > 0 you can assume it is on that Tab.
VB Code:
Dim x As Control
Dim lngTab As Long
For Each x In Controls
If x.Container.Name = "SSTab1" Then
For lngTab = 0 To SSTab1.Tabs - 1
SSTab1.Tab = lngTab ' set current tab
If x.Left > 0 Then
Debug.Print x.Name; " is on tab "; lngTab
Exit For
End If
Next
End If
Next
Just another reason I always recommend to use a Frame Control on each Tab and place the controls in the Frame.
-
Feb 9th, 2006, 05:09 PM
#5
Hyperactive Member
Re: SSTab as a Container
You can place the controls on each tab in a Frame wih no border
To deny our own impulses is to deny the very thing that makes us human
-
Feb 9th, 2006, 05:29 PM
#6
Thread Starter
New Member
Re: SSTab as a Container
There are frames in the tabs with controls inside them and the code above didn't work.
-
Feb 9th, 2006, 05:42 PM
#7
Hyperactive Member
Re: SSTab as a Container
I have a form with a SSTab containing a Frame that has a textbox in it. When I use your function like this
VB Code:
setControls Me, "Frame1", "Hello"
It does work
To deny our own impulses is to deny the very thing that makes us human
-
Feb 9th, 2006, 06:06 PM
#8
Re: SSTab as a Container
the code above didn't work.
Can you explain what you mean by "didn't work"?
-
Feb 9th, 2006, 06:15 PM
#9
Thread Starter
New Member
Re: SSTab as a Container
I placed a control in the second tab and it says that is in the 1st one
-
Feb 9th, 2006, 06:28 PM
#10
Hyperactive Member
Re: SSTab as a Container
the tab indexes are 0 based, thus the tab with index 1 is the second tab
To deny our own impulses is to deny the very thing that makes us human
-
Feb 10th, 2006, 09:45 AM
#11
Thread Starter
New Member
Re: SSTab as a Container
Of course, maybe I should've said:
"I placed a control in the 9th tab and it says that is in the 1st one"
It doesn't matter where you place it. It always says its the 1st one (that is the 0 tab of course )
VB Code:
setControls Me, "Frame1", "Hello"
I know the function works, but that isn't the problem. The problem is to know if a control is on a specific tab inside the SSTab control.
What I was really trying to do I have done in VB .NET and that is to make a function that recursively goes through a container looking for its children and its children's children and so on.
Lets supose I have a frame with frames inside, and those frames have frames inside, and these have textboxes. How can I change the text in the textboxes in just one call, using the frame name that contains all the frames as an argument?
-
Feb 10th, 2006, 12:19 PM
#12
Hyperactive Member
Re: SSTab as a Container
You can't go recursive through the children, but you can go through the containers of the controls recusive .
I made a form with a SStab with a frame in tab 1 and textboxes al over the place. It also works for frames within frames.
VB Code:
Private Sub Command1_Click()
ChangeText Me.Name, "I am on the form" 'Change the text of all te textboxes
ChangeText SSTab1.Name, "I am on the Tab control" 'Change the text of the textboxes on the sstab
ChangeText Frame1.Name, "I am on tab 1" 'change the text of the textboxes inside frame1
End Sub
Private Sub ChangeText(strContainer As String, text As String)
Dim objControl As control
Dim objContainer As control
For Each objControl In Me.Controls
If TypeName(objControl) = "TextBox" Then
Set objContainer = objControl
While (objContainer.container.Name <> strContainer) And (objContainer.container.Name <> Me.Name)
Set objContainer = objContainer.container
Wend
If objContainer.container.Name = strContainer Then
objControl.text = text
End If
End If
Next objControl
End Sub
To deny our own impulses is to deny the very thing that makes us human
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
|