📄 splitter.ctl
字号:
newPos = RatioToPos(UserControl.ScaleHeight, RatioFromTop)
End Select
newPos = VerifyNewPos(UserControl.ScaleHeight, newPos)
picSplitter.Move 0, newPos, AvailableAuxSpace, SplitterSize
CurrSplitterPos = newPos
End Select
End Sub
Private Sub UpdateSplitter()
Select Case Maintain
Case MN_POS
CurrSplitterPos = SplitterPos
Case MN_RATIO
CurrRatioFromTop = RatioFromTop
End Select
End Sub
Private Function VerifyNewPos(availableSpace As Integer, pos As Integer) As Integer
'-------------------- Variables --------------------
Dim newPos As Integer
Dim lowerBound As Integer
Dim size1Violated As Boolean
'-------------------- Code --------------------
If availableSpace > MinRequiredSpace Then
newPos = pos
'Correct bounds if needed
If newPos < 0 Then
newPos = 0
End If
If (newPos + SplitterSize) > availableSpace Then
newPos = availableSpace - SplitterSize
End If
'Check MaxSize
If MaxSize > 0 Then
Select Case MaxSizeAppliesTo
Case MX_CHILD1
If newPos > MaxSize Then
newPos = MaxSize
End If
Case MX_CHILD2
lowerBound = availableSpace - MaxSize - SplitterSize
If newPos < lowerBound Then
newPos = lowerBound
End If
End Select
End If
'See if Child1 bounds violated
size1Violated = False
If newPos <= MinSize1 Then
newPos = MinSize1
size1Violated = True
End If
'See if Child2 bounds violated
If Not size1Violated Then
If (newPos + SplitterSize) > (availableSpace - MinSize2) Then
newPos = availableSpace - MinSize2 - SplitterSize
End If
End If
Else
newPos = MinSize1
End If
VerifyNewPos = newPos
End Function
Public Property Get BorderStyle() As BorderConstants
Attribute BorderStyle.VB_Description = "Returns/sets the border style for the control."
Attribute BorderStyle.VB_ProcData.VB_Invoke_Property = ";Appearance"
BorderStyle = UserControl.BorderStyle
End Property
Public Property Let BorderStyle(value As BorderConstants)
UserControl.BorderStyle = value
PropertyChanged kStrBorderStyle
UserControl_Resize
End Property
Public Property Get SplitterAppearance() As AppearanceConstants
Attribute SplitterAppearance.VB_Description = "The appearance of the splitter bar, only used while the splitter bar is moving and LiveUpdate is false."
Attribute SplitterAppearance.VB_ProcData.VB_Invoke_Property = ";Appearance"
SplitterAppearance = mSplitterAppearance
End Property
Public Property Let SplitterAppearance(value As AppearanceConstants)
mSplitterAppearance = value
PropertyChanged kStrSplitterAppearance
End Property
Public Property Get SplitterBorder() As BorderConstants
Attribute SplitterBorder.VB_Description = "The border style for the spiltter bar, only used while the splitter bar is moving and LiveUpdate is false."
Attribute SplitterBorder.VB_ProcData.VB_Invoke_Property = ";Appearance"
SplitterBorder = mSplitterBorder
End Property
Public Property Let SplitterBorder(value As BorderConstants)
mSplitterBorder = value
PropertyChanged kStrSplitterBorder
End Property
Public Property Get SplitterColor() As OLE_COLOR
Attribute SplitterColor.VB_Description = "The color of the splitter bar, only used while the splitter bar is moving and LiveUpdate is false."
Attribute SplitterColor.VB_ProcData.VB_Invoke_Property = ";Appearance"
SplitterColor = mSplitterColor
End Property
Public Property Let SplitterColor(value As OLE_COLOR)
mSplitterColor = value
PropertyChanged kstrSplitterColor
End Property
Public Property Get Orientation() As OrientationConstants
Attribute Orientation.VB_Description = "The flow of the child controls."
Attribute Orientation.VB_ProcData.VB_Invoke_Property = ";Position"
Orientation = mOrientation
End Property
Public Property Let Orientation(value As OrientationConstants)
Dim oldPos As Integer
oldPos = CurrSplitterPos
mOrientation = value
Select Case mOrientation
Case OC_HORIZONTAL
picSplitter.MousePointer = vbSizeWE
Case OC_VERTICAL
picSplitter.MousePointer = vbSizeNS
End Select
If Maintain = MN_POS Then
CurrSplitterPos = oldPos
End If
PropertyChanged kStrOrientation
UserControl_Resize
End Property
Public Property Get SplitterSize() As Integer
Attribute SplitterSize.VB_Description = "Returns/sets the size of the splitter bar."
Attribute SplitterSize.VB_ProcData.VB_Invoke_Property = ";Position"
SplitterSize = mSplitterSize
End Property
Public Property Let SplitterSize(value As Integer)
If value >= 0 Then
mSplitterSize = value
Else
mSplitterSize = 0
End If
PropertyChanged kStrSplitterSize
MinRequiredSpace = CalcMinRequiredSpace
UserControl_Resize
End Property
Public Property Get Maintain() As MaintainConstants
Attribute Maintain.VB_Description = "Determines how the splitter bar changes when the control is resized."
Attribute Maintain.VB_ProcData.VB_Invoke_Property = ";Behavior"
Maintain = mMaintain
End Property
Public Property Let Maintain(value As MaintainConstants)
mMaintain = value
PropertyChanged kstrMaintain
UpdateSplitter
End Property
Public Property Get SplitterPos() As Integer
Attribute SplitterPos.VB_Description = "Returns/sets the desired position of the splitter bar."
Attribute SplitterPos.VB_ProcData.VB_Invoke_Property = ";Position"
SplitterPos = mSplitterPos
End Property
Public Property Let SplitterPos(value As Integer)
If (gBusy And kBusySplitterPos) = 0 Then
gBusy = gBusy + kBusySplitterPos
If value >= 0 Then
mSplitterPos = value
Else
mSplitterPos = 0
End If
PropertyChanged kStrSplitterPos
'SplitterPos and RatioFromTop update each other, must prevent an infinite loop
If (gBusy And kBusyRatioFromTop) = 0 Then
RatioFromTop = PosToRatio(GetAvailableSpace, mSplitterPos)
CurrSplitterPos = mSplitterPos
End If
gBusy = gBusy - kBusySplitterPos
End If
End Property
Public Property Get CurrSplitterPos() As Integer
Attribute CurrSplitterPos.VB_Description = "Returns the current position of the splitter bar."
Select Case Orientation
Case OC_HORIZONTAL
CurrSplitterPos = picSplitter.Left
Case OC_VERTICAL
CurrSplitterPos = picSplitter.Top
End Select
End Property
Private Property Let CurrSplitterPos(value As Integer)
Dim newPos As Integer
If (gBusy And kBusyCurrSplitterPos) = 0 Then
gBusy = gBusy + kBusyCurrSplitterPos
If value >= 0 Then
newPos = value
Else
newPos = 0
End If
Select Case Orientation
Case OC_HORIZONTAL
picSplitter.Left = VerifyNewPos(UserControl.ScaleWidth, newPos)
CurrRatioFromTop = PosToRatio(UserControl.ScaleWidth, picSplitter.Left)
Case OC_VERTICAL
picSplitter.Top = VerifyNewPos(UserControl.ScaleHeight, newPos)
CurrRatioFromTop = PosToRatio(UserControl.ScaleHeight, picSplitter.Top)
End Select
If (gBusy And kBusyCurrRatioFromTop) = 0 Then
ResizeChildren
End If
gBusy = gBusy - kBusyCurrSplitterPos
End If
End Property
Public Property Get RatioFromTop() As Single
Attribute RatioFromTop.VB_Description = "Returns/sets the desired percentage from the top/left to place the splitter bar."
Attribute RatioFromTop.VB_ProcData.VB_Invoke_Property = ";Position"
RatioFromTop = mRatioFromTop
End Property
Public Property Let RatioFromTop(value As Single)
If (gBusy And kBusyRatioFromTop) = 0 Then
gBusy = gBusy + kBusyRatioFromTop
Select Case True
Case (value >= 0) And (value <= 1)
mRatioFromTop = value
Case value < 0
mRatioFromTop = 0
Case Else
mRatioFromTop = 1
End Select
PropertyChanged kStrRatioFromTop
'SplitterPos and RatioFromTop update each other, must prevent an infinite loop
If (gBusy And kBusySplitterPos) = 0 Then
SplitterPos = RatioToPos(GetAvailableSpace, RatioFromTop)
CurrRatioFromTop = RatioFromTop
End If
gBusy = gBusy - kBusyRatioFromTop
End If
End Property
Public Property Get CurrRatioFromTop() As Single
Attribute CurrRatioFromTop.VB_Description = "Returns the current percentage from the top/left of the splitter bar."
CurrRatioFromTop = mCurrRatioFromTop
End Property
Private Property Let CurrRatioFromTop(value As Single)
Dim newRatio As Single
Dim availableSpace As Integer
If (gBusy And kBusyCurrRatioFromTop) = 0 Then
gBusy = gBusy + kBusyCurrRatioFromTop
Select Case True
Case (value >= 0) And (value <= 1)
newRatio = value
Case value < 0
newRatio = 0
Case Else
newRatio = 1
End Select
availableSpace = GetAvailableSpace
CurrSplitterPos = VerifyNewPos(availableSpace, RatioToPos(availableSpace, newRatio))
mCurrRatioFromTop = PosToRatio(availableSpace, CurrSplitterPos)
If (gBusy And kBusyCurrSplitterPos) = 0 Then
ResizeChildren
End If
gBusy = gBusy - kBusyCurrRatioFromTop
End If
End Property
Public Property Get Child1() As String
Attribute Child1.VB_Description = "Returns/sets the name of the control to appear at the left/top."
Attribute Child1.VB_ProcData.VB_Invoke_Property = ";Misc"
Child1 = mChild1
End Property
Public Property Let Child1(value As String)
mChild1 = value
PropertyChanged kStrChild1
ResizeChildren
End Property
Private Property Get objChild1() As Object
'-------------------- Variables --------------------
Dim found As Boolean
Dim i As Integer
'-------------------- Code --------------------
If Child1 <> "" Then
found = False
For i = 0 To UserControl.ContainedControls.Count - 1
If UserControl.ContainedControls(i).Name = Child1 Then
Set objChild1 = UserControl.ContainedControls(i)
found = True
Exit For
End If
Next
If Not found Then
Set objChild1 = Nothing
End If
Else
Set objChild1 = Nothing
End If
End Property
Public Property Get Child2() As String
Attribute Child2.VB_Description = "Returns/sets the name of the control to appear at the right/bottom."
Attribute Child2.VB_ProcData.VB_Invoke_Property = ";Misc"
Child2 = mChild2
End Property
Public Property Let Child2(value As String)
mChild2 = value
PropertyChanged kStrChild2
ResizeChildren
End Property
Private Property Get objChild2() As Object
'-------------------- Variables --------------------
Dim found As Boolean
Dim i As Integer
'-------------------- Code --------------------
If Child2 <> "" Then
found = False
For i = 0 To UserControl.ContainedControls.Count - 1
If UserControl.ContainedControls(i).Name = Child2 Then
Set objChild2 = UserControl.ContainedControls(i)
found = True
Exit For
End If
Next
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -