Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
BarColor In WeekView and MonthViewSingle

I know that the BarColor property of the appointment object does not exist in the WeekView or the MonthViewSingle.  I have added a creation filter to the week and month views to try to simulate the BarColor that exists in the day view  I also am adding a couple of buttons to the appointment as well.  This code is working, however I seem to be running into some sort of screen refresh problem.  Once I change a view from week to month, my buttons appear properly, but my colored rectangle disappears.  If I move the mouse around, the colors magically appear.

I know this is a refresh problem, but I have put refreshes all over my code to no avail.  What's curious is that the buttons display properly all the time.  It's just the colored rectangle that disappears.  Of course, I'd love to see the BarColor property built directly into the Week and Month views, but until then I am happy with this work-around.  Here is my code that adds the colored rectangle.  I've also attached a screen cap.

Private Sub AddBarColorUIElement(ByRef objUIElement As UIElement, ByRef objAppointment As Appointment, ByVal objWeekView As UltraWeekView, ByVal objColor As Color)




'this sub adds a UIElement to the CreationFilter...

If Not IsNothing(objColor) Then





'create an instance of E2WeekViewUIElement to place a button in the appointment...

Dim objNewWeekViewUIElement As New E2WeekViewUIElementobjUIElement.Parent)

objNewWeekViewUIElement.Appointment = objAppointment

objNewWeekViewUIElement.WeekView = objWeekView





'IMPORTANT! position the custom UIElement using its Rect property...

objNewWeekViewUIElement.Rect = New Rectangle(objUIElement.RectInsideBorders.X, objUIElement.RectInsideBorders.Y, intBarColorWidth, objUIElement.RectInsideBorders.Height)



If Not IsNothing(objColor) Then





'fill the rectangle with the barcolor of the appointment...

Dim gr As Graphics = objWeekView.CreateGraphics





Dim SolidBrush As New SolidBrush(objColor)

gr.FillRectangle(SolidBrush, objNewWeekViewUIElement.Rect)



End If




'add the custom UIElement to its parent's ChildElements collection...




End If


End Sub

  • 69832
    Offline posted

    It looks like you are doing the painting for the E2WeekViewUIElement right in the AddBarColorUIElement routine, which I assume gets called from the IUIElementCreationFilter.AfterCreateChildElements method. There is a separate interface, IUIElementDrawFilter, which you can use to do custom drawing, but I don;t think you want to do that here.

    What you should do is override the DrawBackColor method for your E2WeekViewUIElement  class, and use the FillRectangle method therein. The DrawBackColor gets called whenever the element is updated, i.e., when a WM_PAINT message is processed an that element lies within the invalidation area. The problem you are currently having stems from the fact that the IUIElementCreationFilter.AfterCreateChildElements method is called before the control processes its paint messages.

    Also, I know this is an incomplete code sample and it is entirely possible you are taking care of this already, but I noticed that you are creating a Graphics object (via the objWeekView.CreateGraphics method) and a SolidBrush object, but neither of these are being disposed of, which can create a GDI+ resource leak. What some folks do is place the drawing code in a 'Using' block, which disposes of the object created therein after the code executes

    Using gr As Graphics = objWeekView.CreateGraphics()
        Using SolidBrush As New SolidBrush(objColor)
            gr.FillRectangle(SolidBrush, objNewWeekViewUIElement.Rect)
        End Using
    End Using

Reply Children
No Data