📄 scrllngfrm.ctl
字号:
'The following sub will go trough all the visible
'controls of the form and will try to figure which
'ones are within the PictureBox that corresponds
'to the current page. Then, the sub will try to
'determine which control has the smallest TabIndex
'and will select this control as long as this is the
'first time the user is opening the current page
'(PuctureBox). However, if this is not the first
'time that the user has visited the current page
'(PictureBox), this sub will select the Control
'last selected on the current page.
Private Sub subSelectFirst()
Dim intForm As Form
Dim intControl As Control
Dim intContName As String
Dim intContIndex As String
Dim intContHWnd As Long
Dim intContTabInd As Integer
Dim intContTabStop As Boolean
Dim intFirstControl As Boolean
Dim intPage As Integer
Dim intHasHWnd As Variant
Dim intIsNewPage As Boolean
Dim intTempIndex As String
Dim intContainerName As String
Dim intContanierIndex As String
Dim intContanier As Control
Dim i As Integer
intFirstControl = True
'This If Then statement will only be true if there
'was no page (PictureBox) added to the Control.
If (m_HowManyPages = 0) Then
If Not (intSetFocus) Then
m_HowManyPages = 1
Else
intSetFocus = False
Exit Sub
End If
End If
'Find out whether the user is adding a new page
'or is trying to go to a page that has already
'been added.
For i = 0 To m_HowManyPages - 1
If (Len(FirstControl(1, i)) = 0) _
And (i = 0) Then
intPage = 0
intIsNewPage = True
Exit For
ElseIf (FirstControl(1, i) = pChild.hwnd) Then
intPage = i
Exit For
ElseIf (i = m_HowManyPages - 1) Then
intPage = m_HowManyPages
intIsNewPage = True
End If
Next i
'If another page is added, re-dimension
'the array to hold this extra information.
If (intPage = m_HowManyPages) Then
ReDim Preserve FirstControl(8, intPage + 1)
m_HowManyPages = m_HowManyPages + 1
End If
'Update the current page...
currPage = intPage
'Get a hold on the Form where this
'UserControl is.
Set intForm = pChild.Parent
'Loop through all the controls on
'the Parent Form.
For i = 0 To intForm.Controls.Count - 1
Set intControl = intForm.Controls(i)
'Some properties may not be available, depending on
'the control that is selected. For example, if the
'selected control is a Timer, you cannot check its
'type without getting an error. As a result, I added
'the following error handling line. It is worth
'mentioning that I didn't use the common error
'handling line "On Error Resume Next". If I did,
'every time I got an error on the If Then conditional
'I would have an undesirable behavior. Instead of
'skipping the conditional, the process would go right
'through it! To avoid this, I stated on my error
'handling line that I wanted the process to jump to
'the end of the For Next loop (thus skipping the If
'Then statement) and, then, Resume Next from there.
On Error GoTo NextLoop
If (intControl.Visible) _
And Not (TypeOf intControl Is Label) _
And Not (TypeOf intControl Is Frame) Then
'There are some controls like Labels that
'don't have the hWnd property. I used this
'error handling to bypass an error that
'was going to occur if I tried to read this
'property form such controls.
On Error Resume Next
intHasHWnd = Empty
intHasHWnd = intControl.hwnd
'If Control has a Windows handle number (hWnd)...
If Not (IsEmpty(intHasHWnd)) Then
'I was having problems when the selected
'Control was a Timer. The Timer has no container.
'Therefore, I needed to check the name of the
'container before going any further.
intContainerName = ""
intContainerName = CStr(intControl.Container.Name)
If (Len(intContainerName) > 0) Then
'The control should be the contained by
'the PictureBox (Current Page).
If (intControl.Container.hwnd <> intForm.hwnd) Then
If (intControl.Container.hwnd = pChild.hwnd) Then
'There are some controls like Frames and
'Labels that don't have the TabStop property.
'If I tried to read this property from
'such controls, I would get an error message.
'However, because I wrote the error handling
'line before, this error will be bypassed.
intContTabStop = False
intContTabStop = intControl.TabStop
If (intFirstControl) _
And (intContTabStop) Then
intContTabInd = intControl.TabIndex
intFirstControl = False
End If
'Check whether the currently selected control
'has a TabIndex smaller then the previously
'saved control or not.
If (intControl.TabIndex <= intContTabInd) _
And (intContTabStop) Then
intContTabStop = False
intContTabInd = intControl.TabIndex
intContName = intControl.Name
intContHWnd = intControl.hwnd
intContIndex = ""
intContIndex = CStr(intControl.Index)
End If
'If the container of the currently selected
'control is not the PictureBox(Current Page),
'select the container of this Control and verify
'if the container of this container is the
'PictureBox. If so, it will mean that, even
'though this control is not directly an object
'contained by the Page (PictureBox), it will
'still be considered as a member of the page
'because its container is part of the PictueBox
'collection.
'Summarizing, this function will allow
'the user to use frames on each page.
Else
'Now, I will check if the currently selected
'object is part of an Array or not. I just
'check if the currently selected control has
'an Index number. If it has an Index number,
'I will know that it is part of an array. However,
'if it doesn't have a number, it will give me an
'error. That's why I put this error handling line.
'There might be a cleaner way to figure it out.
'However, after doing a thorough research, I didn't
'find anything better then this. If you know a
'better way of figuring out whether a control is
'par of an array or not, please, send me an e-mail
'or post a feedback. :)
intContanierIndex = ""
intContanierIndex = CStr(intControl.Container.Index)
If (Len(intContanierIndex) = 0) Then
'Select the control using the following statement
'if the control is NOT part of an array.
Set intContanier = intForm.Controls(intContainerName)
Else
'Select the control using the following statement
'if the control is part of an array.
Set intContanier = intForm.Controls(intContainerName).Item(CInt(intContanierIndex))
End If
If (intContanier.Container.hwnd = pChild.hwnd) Then
'There are some controls like Frames and Labels
'that don't have the TabStop property. If I tried
'to read this property from such controls, I would
'get an error message. However, because I wrote
'the error handling line before, this error will
'be bypassed.
intContTabStop = False
intContTabStop = intControl.TabStop
If (intFirstControl) _
And (intContTabStop) Then
intContTabInd = intControl.TabIndex
intFirstControl = False
End If
'Check whether the currently selected control has
'a TabIndex smaller then the previously saved
'control or not.
If (intControl.TabIndex <= intContTabInd) _
And (intContTabStop) Then
intContTabStop = False
intContTabInd = intControl.TabIndex
intContName = intControl.Name
intContHWnd = intControl.hwnd
'Now, I will check if the currently selected
'object is part of an Array or not. I just check
'if the currently selected control has an Index
'number. If it has an Index number, I will know
'that it is part of an array. However, if it
'doesn't have a number, it will give me an error.
'That's why I put this error handling line. There
'might be a cleaner way to figure it out. However,
'after doing a thorough research, I didn't find
'anything better then this. If you know a better
'way of figuring out whether a control is par of
'an array or not, please, send me an e-mail or
'post a feedback. :)
intContIndex = ""
intContIndex = CStr(intControl.Index)
End If
End If
End If
End If
End If
End If
End If
NextLoop:
Resume Next
Next i
'If it is a page that has just been added,
'select the control with the smallest TabIndex
'contained by the current page (PictureBox).
If ((intIsNewPage) _
Or (FirstControl(2, intPage) = "This is a new Page.")) Then
FirstControl(1, intPage) = pChild.hwnd
FirstControl(2, intPage) = intContName
FirstControl(3, intPage) = intContIndex
FirstControl(4, intPage) = intContHWnd
FirstControl(5, intPage) = 1
FirstControl(6, intPage) = 1
FirstControl(7, intPage) = pChild.Name
'Now, I will check if the currently selected
'object is part of an Array or not. I just check
'if the currently selected control has an Index
'number. If it has an Index number, I will know
'that it is part of an array. However, if it
'doesn't have a number, it will give me an error.
'That's why I put this error handling line. There
'might be a cleaner way to figure it out. However,
'after doing a thorough research, I didn't find
'anything better then this. If you know a better
'way of figuring out whether a control is par of
'an array or not, please, send me an e-mail or
'post a feedback. :)
On Error Resume Next
intTempIndex = ""
intTempIndex = CStr(pChild.Index)
FirstControl(8, intPage) = intTempIndex
VScroll.Value = FirstControl(5, intPage)
HScroll.Value = FirstControl(6, intPage)
'If it is a page that has been visited before,
'select the control was last select on the current
'page (PictureBox).
Else
'If the user chose not to have the UserControl
'memorizing the position of the Scroll Bars on
'last visit to the page, reset these values on
'the array.
If Not (m_MemorizeScroll) Then
FirstControl(5, intPage) = 1
FirstControl(6, intPage) = 1
End If
'If the user choses not to have the UserControl
'memorizing the last selected Control on last
'visit to the page current page, select the control
'with the smallest TabIndex contained by the
'current page (PictureBox).
If Not (m_MemorizeField) Then
FirstControl(2, intPage) = intContName
FirstControl(3, intPage) = intContIndex
End If
intContName = FirstControl(2, intPage)
intContIndex = FirstControl(3, intPage)
VScroll.Value = FirstControl(5, intPage)
HScroll.Value = FirstControl(6, intPage)
End If
If (Len(intContIndex) = 0) Then
'Select the control using the following
'statement if the control is NOT part of
'an array.
intForm.Controls(intContName).SetFocus
Else
'Select the control using the following
'statement if the control is part of an
'array.
Set intControl = intForm.Controls(intContName).Item(CInt(intContIndex))
intControl.SetFocus
End If
End Sub
'======================================
'==== The following subs are used ====
'==== to navigate through each of ====
'==== the added pages (PictureBox) ====
'======================================
'Validate the NextPage request and call the
'subCallAttach sub only if going to next page
'is possible.
Public Sub NextPage()
Dim intPage As Integer
If Not (Len(FirstControl(1, 0)) > 0) Then
Exit Sub
ElseIf (currPage + 1 < m_HowManyPages) Then
intPage = currPage + 1
Else
intPage = currPage
End If
Call subCallAttach(intPage)
End Sub
'Validate the PreviousPage request and call
'the subCallAttach sub only if going to
'previous page is possible.
Public Sub PreviousPage()
Dim intPage As Integer
If Not (Len(FirstControl(1, 0)) > 0) Then
Exit Sub
ElseIf (currPage > 0) Then
intPage = currPage - 1
Else
intPage = currPage
End If
Call subCallAttach(intPage)
End Sub
'Validate the FirstPage request and call the
'subCallAttach sub only if going to next
'page is possible.
Public Sub FirstPage()
Dim intPage As Integer
If Not (Len(FirstControl(1, 0)) > 0) Then
Exit Sub
End If
Call subCallAttach(intPage)
End Sub
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -