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)
'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...
objUIElement.Parent.ChildElements.Add(objNewWeekViewUIElement)
End Sub
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
Example:Using gr As Graphics = objWeekView.CreateGraphics() Using SolidBrush As New SolidBrush(objColor) gr.FillRectangle(SolidBrush, objNewWeekViewUIElement.Rect) End UsingEnd Using
Brian:
I found the DrawBackColor method, but didn't find a FillRectangle method in it or on the DrawParams parameter. Can you steer me toward where I might find the FillRectangle method?
I found it, Brian, on the Graphics property of the drawParams parameter. Thanks for your help!
One last detail: How do I emulate the rounded border on the top and bottom? I have seen some posts that talk about BorderSides, but can't seem to find any sample code that shows how to do it. Is that the best approach?
rehemann said:I found it, Brian, on the Graphics property of the drawParams parameter.
Sorry, I must have been unclear about this. What I meant was, in your E2WeekViewUIElement class implementation, which derives from the Infragistics.Win.UIElement class, you should override the DrawBackColor method, so that this overridden implementation is used whenever the control draws itself.