Show

Creating and assigning bar styles in ctSchedule


 

By default, a time bar is 10 pixels less in height than its host list item (5 pixels from the top and 5 from the bottom) and is vertically centered within the host item. Its color is determined by the BarDefBackColor property, and it initially contains no text and no images on either side of the bar.

However, a bar can be set up with different heights, distances from the center of the vertical offset, text, and images on both sides of the bar. This control allows the programmer to create and store up to 32,000 different bar styles. While that many bar styles may be a bit excessive, there may be many instances where a few different styles are required. (i.e. Scheduling regular employee hours of work with one style, and then their breaks with another.)

Adding the Time Bar Style

A bar style is initially created using the AddBarStyle method. This method accepts two parameters. The first determines the height of the time bar. The second determines its offset from the vertical center of the host item. A positive value will move the bar down and a negative value will move it up. With that in mind, the programmer should take care not to move a bar outside of its host item. If successful, the AddBarStyle method return the new index value of the time bar. This index value is required to further enhance the bar style.

Images
It is also possible to add images to each end of a time bar. In order to add an image to the time bar style, we use the StyleStartImage and StyleEndImage properties.  The internal image list is able to hold up to 100 different images.  You may want to use icons as custom images instead of bitmaps since icons can contain a transparent area. If you use a bitmap with an odd shape, it may display the entire rectangular region of the bitmap. Bitmaps can also be set up with transparency using the MaskBitmap and MaskColor properties.  The control also contains 15 custom icons. The custom icons can be displayed by assigning the negative numbers 1 - 15 to the StyleStartImage and StyleEndImage properties.  The first five custom icons are triangles pointing down. The next five are triangles pointing up and the next five custom icons are triangles. The come in the following colors ... Blue, aqua, red, grey, and white.
The StyleEndFront, StyleEndXOffset, StyleEndYOffset, StyleStartFront, StyleStartXOffset, and StyleStartYOffset properties are all used to help position an image on the end of a bar. The programmer might have to experiment a little with these properties before they are satisfied with the look of a particular style.

Colors
The color of a background and text of a time bar are first defined by the BarBackColor and BarForeColor properties respectively. If these properties are set to a value of -1, then the colors are defined by the StyleBackColor and StyleForeColor properties. Finally, if these properties are set to a value of -1, the colors are then defined by the BarDefBackColor and BarDefForeColor properties when the bar is originally created.

Text
The text within a time bar is not actually part of a style. It is created through the BarText property. However, the position of the text can be altered through the StyleTextXOffset and StyleTextYOffset properties.

Milestones

A milestone is a special type of bar style. A bar style is defined as a milestone using the StyleMilestone property. Milestones represent a certain place in time. Therefore, the starting and ending dates and times for a milestone are identical. Time bars marked as milestones cannot be re-sized. They can only be moved.

Note : A milestone bar style means that the bar itself will be very thin. It will be too thin to place text or color into it. By default, milestone bars will have any text assigned to it displayed to the right of the bar. It will be the responsibility of the programmer to prevent the text from then being displayed within the bar. As well, in order to see a time bar more easily, it may be a good idea to assign an image to one side of the bar. (See above for information on images)

Assigning a Style to a Bar
After a bar style has been created, it must then be assigned to a bar. The DefaultStyle property can be used for this. It is used to determine what bar style is assigned to new time bar. If a value of 0, or a value greater then the current amount of defined bar styles is assigned to that property, a default time bar will be assigned. The time bar style of a bar can be changed at any other time using the BarStyle property.

Note : If a time bar style is deleted, the appearance of any time bar with an index value greater than or equal to that of the deleted style may change. It will be the programmer’s responsibility to adjust the time bar styles of the bars in question.
 

Example:
 

Private Sub ctSchedule1_FirstDraw()
Dim nIndex As Integer 'Specifies the index of the list items
Dim nStyle As Integer 'Specifies the index of the bar styles
Dim nBar As Integer 'Specifies the index of the time bars
 
'The following will create a new bar style
nStyle = ctSchedule1.AddBarStyle(12, 0)
Me.ctSchedule1.StyleBackColor(nStyle) = RGB(255, 255, 255)
Me.ctSchedule1.StyleStartImage(nStyle) = -1
Me.ctSchedule1.StyleEndImage(nStyle) = -1
 
'The following will add an item and a time bar to the control
nIndex = ctSchedule1.AddItem("Item 1")
nBar = ctSchedule1.AddTimeBar(nIndex, 120, 180, -1, -1)
ctSchedule1.BarText(nIndex, nBar) = "Text"
 
'Center the text in the time bar
Me.ctSchedule1.BarTextAlign(nIndex, nBar) = 2
 
'Assign the time bar a style
Me.ctSchedule1.BarStyle(nIndex, nBar) = nStyle
End Sub