Imports Infragistics.Win
Imports Infragistics.Win.UltraWinSchedule
Imports Infragistics.Win.UltraWinEditors
Imports System.Drawing.Drawing2D
' <summary>
' UltraComboEditor-derived class which emulates a color-picker
' for the purpose of providing the end user with a way to select
' Outlook2007ColorScheme instances.
' </summary>
Public Class Outlook2007ColorSchemeDropDown
Inherits UltraComboEditor
Private Shared ReadOnly defaultItemHeight As Integer = 18
Private _calendarLook As UltraCalendarLook = Nothing
Public Sub New(ByVal parent As Control, ByVal calendarLook As UltraCalendarLook)
MyBase.New()
If parent Is Nothing Then Throw New ArgumentNullException()
If calendarLook Is Nothing Then Throw New ArgumentNullException()
Me._calendarLook = calendarLook
' Set the DropDownStyle to DropDownList so the end user
' can only select items from the list.
Me.DropDownStyle = DropDownStyle.DropDownList
' Set some of the properties of the ValueList
' so that we only display an image of the color
Dim ValueList As ValueList = Me.Items.ValueList
ValueList.DisplayStyle = ValueListDisplayStyle.Picture
ValueList.ItemHeight = Outlook2007ColorSchemeDropDown.defaultItemHeight
ValueList.ScaleItemImage = ScaleImage.Never
' Populate the list
Me.PopulateList()
' Add the control to the parent Controls collection
parent.Controls.Add(Me)
End Sub
' <summary>
' Gets/sets the UltraCalendarLook component associated with this Outlook2007ColorSchemeDropDown instance.
' </summary>
Public Property CalendarLook() As UltraCalendarLook
Get
Return Me._calendarLook
End Get
Set(ByVal Value As UltraCalendarLook)
If Not Value Is Me._calendarLook Then
Me._calendarLook = Value
Me.PopulateList()
End If
End Set
End Property
Public Property SelectedColorScheme() As Outlook2007ColorScheme
Get
Dim selectedItem As ValueListItem = Me.SelectedItem
Return IIf(Not selectedItem Is Nothing, selectedItem.DataValue, Nothing)
End Get
Set(ByVal Value As Outlook2007ColorScheme)
Dim selectedIndex As Integer = -1
If Value Is Nothing Then
selectedIndex = -1
Else
Dim items As ValueListItemsCollection = Me.Items
Dim i As Integer
For i = 0 To items.Count - 1
Dim item As ValueListItem = items(i)
Dim colorScheme As Outlook2007ColorScheme = item.DataValue
If (Value Is colorScheme) Then
selectedIndex = i
Exit For
End If
Next
Me.SelectedIndex = selectedIndex
End If
End Set
End Property
Private Sub PopulateList()
' Clear the Items collection
Dim items As ValueListItemsCollection = Me.Items
items.Clear()
If (Me.CalendarLook Is Nothing) Then Return
' Get the width and height to use for the images we are going to generate
Dim width As Integer = Me.Width - 2
Dim height As Integer = Outlook2007ColorSchemeDropDown.defaultItemHeight
' Iterate the members of the CalendarLook's Outlook2007ColorSchemes
' collection...add an item to the Items collection for each color scheme
Dim colorSchemes As Outlook2007ColorSchemeCollection = Me.CalendarLook.Outlook2007ColorSchemes
Dim i As Integer
For i = 0 To colorSchemes.Count - 1
' Use the SupportedColors array to index into the
' Outlook2007ColorSchemes collection
Dim colorScheme As Outlook2007ColorScheme = colorSchemes(colorSchemes.SupportedColors(i))
' Add a ValueListItem, and assign the color scheme to its DataValue property.
Dim item As ValueListItem = items.Add(colorScheme)
' Get the colors we will use to represent this color scheme
Dim backColor As Color = colorScheme.AppointmentBackColor2
Dim backColor2 As Color = colorScheme.BaseColor
Dim borderColor As Color = colorScheme.AppointmentBorderColor
' Create a Bitmap and get a Graphics object for it
Dim bitmap As Bitmap = New Bitmap(width, height)
Dim gr As Graphics = Graphics.FromImage(bitmap)
' Create the Rectangle for the fill colors
Dim rect As Rectangle = New Rectangle(Point.Empty, bitmap.Size)
rect.Inflate(-1, -1)
' Create a LinearGradientBrush with the fill colors,
' and a Pen for the border color.
Dim brush As New LinearGradientBrush(rect, backColor, backColor2, 90.0F)
Dim pen As New Pen(borderColor)
' Fill the Rectangle with the gradient colors
gr.FillRectangle(brush, rect)
' Reduce the width and height of the Rectangle and draw the border
rect.Width -= 1
rect.Height -= 1
gr.DrawRectangle(pen, rect)
' Dispose of the GDI+ objects we created to render the image
brush.Dispose()
pen.Dispose()
gr.Dispose()
' Assign the resulting Bitmap to the ValueListItem's Appearance.Image.
item.Appearance.Image = bitmap
Next
If (items.Count > 0) Then
' Since this is a relatively short list, set the MaxDropDownItems
' property to the number of items in the collection so that no
' scrollbar is shown.
Me.MaxDropDownItems = items.Count
' Select the item which corresponds to the default color scheme
Me.SelectedColorScheme = colorSchemes.DefaultScheme
End If
End Sub
End Class