Dim myItemIndex As Long
'Add an item to the list.
myItemIndex = Me.ctSchedule0.AddItem("Item 1")
'Add a time bar to the item.
Me.ctSchedule0.AddTimeBar myItemIndex, 60, 120,
Me.ctSchedule0.DateStart, Me.ctSchedule0.DateStart
'Add an item to the list.
myItemIndex = Me.ctSchedule0.AddItem("Item 2")
'Add a time bar to the item.
Me.ctSchedule0.AddTimeBar myItemIndex, 180, 240,
Me.ctSchedule0.DateStart, Me.ctSchedule0.DateStart
'Add an item to the list.
myItemIndex = Me.ctSchedule0.AddItem("Item 3")
'Add a time bar to the item.
Me.ctSchedule0.AddTimeBar myItemIndex, 260, 320,
Me.ctSchedule0.DateStart, Me.ctSchedule0.DateStart
'Add an item to the list.
myItemIndex = Me.ctSchedule0.AddItem("Item 4")
'Add a time bar to the item.
Me.ctSchedule0.AddTimeBar myItemIndex, 360, 420,
Me.ctSchedule0.DateStart, Me.ctSchedule0.DateStart
'Add an item to the list.
myItemIndex = Me.ctSchedule0.AddItem("Item 5")
'Add a time bar to the item.
Me.ctSchedule0.AddTimeBar myItemIndex, 120, 180,
Me.ctSchedule0.DateStart, Me.ctSchedule0.DateStart
'Add a barstyle for selected time bars to the
control.
mySelectedBarStyleIndex =
Me.ctSchedule0.AddBarStyle(20, 0)
'Set its back color to green
Me.ctSchedule0.StyleBackColor(mySelectedBarStyleIndex) =
vbGreen
End Sub
Private Sub
ctSchedule0_BarRightClick(ByVal nIndex As Integer, ByVal
nBar As Integer)
'This event fires when a time bar
receives a right mouse click.
'Toggle the selected style on or off.
If Me.ctSchedule0.BarStyle(nIndex, nBar) =
mySelectedBarStyleIndex Then
'Turn the bar style off
Me.ctSchedule0.BarStyle(nIndex, nBar) = 0
Else
'Apply the selected bar style to the time bar
receiving the right click.
Me.ctSchedule0.BarStyle(nIndex, nBar) =
mySelectedBarStyleIndex
End If
End Sub
Private Sub ctSchedule0_BarSelect(ByVal
nIndex As Integer, ByVal nBar As Integer)
'This event fires when a time bar is
selected by left click on it.
myBarSelectedItem = nIndex 'Store the item
index for the time bar in the public variable.
myBarSelectedBar = nBar 'Store the bar index for the
time bar in the public variable.
myBarStartTime = Me.ctSchedule0.BarTimeStart(nIndex,
nBar) 'Store
the Start Time of the time bar in the public variable.
myBarStartDate = Me.ctSchedule0.BarDateStart(nIndex,
nBar) 'Store
the Start Date of the time bar in the public variable.
myBarEndTime = Me.ctSchedule0.BarTimeEnd(nIndex,
nBar) 'Store
the End Time of the time bar in the public variable.
myBarEndDate = Me.ctSchedule0.BarDateEnd(nIndex,
nBar) 'Store
the End Date of the time bar in the public variable.
'NOTE: These public variables are used in the
BarChanged event to determine how far the selected time bar
travelled in order to update the other selected time bars.
End Sub
Private Sub
ctSchedule0_BarChanged(ByVal nIndex As Integer, ByVal nBar
As Integer, ByVal cKeyID As String, ByVal lTimeStart As
Long, ByVal lTimeEnd As Long, ByVal lDateStart As Long,
ByVal lDateEnd As Long)
'This event fires when a time bar is
resized or moved horizontally.
Dim moveSelected As Boolean
moveSelected = False
'Check for a resize
If (lTimeStart <> myBarStartTime) Or (lDateStart <>
myBarStartDate) Then
'The start time has changed
'Test to see if the end time/date has changed
If (lTimeEnd = myBarEndTime) And (lDateEnd =
myBarEndDate) Then
'The end has not moved therefore the bar is being
resized on the front end.
'Do not move the other selected time bars.
moveSelected = False
Else
moveSelected = True
End If
End If
If (Me.ctSchedule0.BarStyle(nIndex, nBar) =
mySelectedBarStyleIndex) And (moveSelected = True) Then
Dim myBarDateDiff As Long
Dim myBarTimeDiff As Long
Dim myBarLeftMove As Boolean
'Calculate the number of days and minutes the bar has
moved by comparing the time bar's final position (lDateStart
and lTimeStart)
'to its starting position (myBarStartDate,
myBarStartTime).
myBarDateDiff = lDateStart - myBarStartDate
myBarTimeDiff = lTimeStart - myBarStartTime
If myBarDateDiff < 0 Then
myBarLeftMove = True
Else
If myBarTimeDiff < 0 Then
myBarLeftMove = True
Else
myBarLeftMove = False
End If
End If
'Apply the changes to the other bars with the same
style
For x = 1 To Me.ctSchedule0.ListCount 'Iterate
through the items in the list.
For y = 1 To Me.ctSchedule0.BarCount(x) 'Iterate
through the bars in the item.
If nIndex = x And nBar = y Then
'This is the bar being moved.
'Set the new start date and time in the public
variables that track the bar moving.
myBarStartTime = lTimeStart
myBarStartDate = lDateStart
myBarEndTime = lTimeEnd
myBarEndDate = lDateEnd
Else
If Me.ctSchedule0.BarStyle(x, y) =
mySelectedBarStyleIndex Then
'The time bar is in a selected state.
'Update the start and end of the time bar according
to the move of the time bar being moved with the mouse.
If myBarLeftMove Then
Dim myBarDuration As Long
Dim myBarDateDelta As Integer
myBarDateDelta = Me.ctSchedule0.BarDateEnd(x, y) -
Me.ctSchedule0.BarDateStart(x, y)
myBarDuration = myBarDateDelta * 24 * 60 +
(Me.ctSchedule0.BarTimeEnd(x, y) -
Me.ctSchedule0.BarTimeStart(x, y))
Dim stopMovingBar As Boolean
stopMovingBar = False
'Set the new start and end times on the time bar
'Apply the number of days moved.
Me.ctSchedule0.BarDateStart(x, y) =
Me.ctSchedule0.BarDateStart(x, y) + myBarDateDiff
If (Me.ctSchedule0.BarTimeStart(x,
y) + myBarTimeDiff) < 0 Then
'The time bar moved over midnight
'Subtract a day and apply the time bar time
difference.
Me.ctSchedule0.BarDateStart(x, y) =
Me.ctSchedule0.BarDateStart(x, y) - 1
Me.ctSchedule0.BarTimeStart(x, y) =
Me.ctSchedule0.BarTimeStart(x, y) + 1440 + myBarTimeDiff
Else
'Apply the time bar time difference.
Me.ctSchedule0.BarTimeStart(x, y) =
Me.ctSchedule0.BarTimeStart(x, y) + myBarTimeDiff
End If
Me.ctSchedule0.BarDateEnd(x, y) =
Me.ctSchedule0.BarDateEnd(x, y) + myBarDateDiff
If Me.ctSchedule0.BarTimeEnd(x, y) + myBarTimeDiff <
0 Then
Me.ctSchedule0.BarDateEnd(x, y) =
Me.ctSchedule0.BarDateEnd(x, y) - 1
Me.ctSchedule0.BarTimeEnd(x,
y) = Me.ctSchedule0.BarTimeEnd(x, y) + 1440 + myBarTimeDiff
Else
Me.ctSchedule0.BarTimeEnd(x, y) =
Me.ctSchedule0.BarTimeEnd(x, y) + myBarTimeDiff
End If
'Test to see if the time bar being moved is before
the start of the schedule.
If Me.ctSchedule0.BarDateStart(x, y) <
Me.ctSchedule0.DateStart Then
'The time bar has been moved prior to the start of
the schedule.
stopMovingBar = True
Else
If (Me.ctSchedule0.BarDateStart(x, y) =
Me.ctSchedule0.DateStart) And
(Me.ctSchedule0.BarTimeStart(x, y) <
Me.ctSchedule0.TimeStart) Then
stopMovingBar = True
End If
End If
If stopMovingBar = True Then
'Make it appear that the time bar has hit the start
of the schedule.
Me.ctSchedule0.BarDateStart(x, y) =
Me.ctSchedule0.DateStart
Me.ctSchedule0.BarTimeStart(x, y) =
Me.ctSchedule0.TimeStart
Me.ctSchedule0.BarTimeEnd(x, y) =
Me.ctSchedule0.BarTimeStart(x, y) + myBarDuration
End If
Else
'Bar is moving right
'Apply the number of days
moved.
Me.ctSchedule0.BarDateStart(x, y) =
Me.ctSchedule0.BarDateStart(x, y) + myBarDateDiff
If Me.ctSchedule0.BarTimeStart(x, y) + myBarTimeDiff
>= 1440 Then
'Time bar moved over midnight
Me.ctSchedule0.BarDateStart(x, y) =
Me.ctSchedule0.BarDateStart(x, y) + 1
Me.ctSchedule0.BarTimeStart(x, y) =
Me.ctSchedule0.BarTimeStart(x, y) - 1440 + myBarTimeDiff
Else
Me.ctSchedule0.BarTimeStart(x, y) =
Me.ctSchedule0.BarTimeStart(x, y) + myBarTimeDiff
End If
'Apply the number of days moved.
Me.ctSchedule0.BarDateEnd(x, y) =
Me.ctSchedule0.BarDateEnd(x, y) + myBarDateDiff
If Me.ctSchedule0.BarTimeEnd(x, y) + myBarTimeDiff >=
1440 Then
'Time bar moved over midnight
Me.ctSchedule0.BarDateEnd(x, y) =
Me.ctSchedule0.BarDateEnd(x, y) + 1
Me.ctSchedule0.BarTimeEnd(x, y) =
Me.ctSchedule0.BarTimeEnd(x, y) - 1440 + myBarTimeDiff
Else
Me.ctSchedule0.BarTimeEnd(x, y) =
Me.ctSchedule0.BarTimeEnd(x, y) + myBarTimeDiff
End If
End If
End If
End If
Next
Next
End If
End Sub